Vim Delete duplicate rows

Source: Internet
Author: User

Reposted Vim Delete duplicate rows

2 related articles are included below

1) posted from: http://kangzye.blog.163.com/blog/static/36819223201061705729933/

Vim finds the same two rows, and deletes duplicate rows

To find the same two rows, sort the contents first, and then find the previous line equals the last line

: Sort

/^\ (. \+\) $\n\1

So found, the profound vim–. –

Delete duplicate rows (first order):

: Sort
: g/^\ (. \+\) $\n\1/d

2) posted from: http://kangzye.blog.163.com/blog/static/36819223201061705729933/

About the duplicate lines in the deleted text of vim.

Recently began to use Vim, feel this is the artifact of the outside world, no wonder so many vimer to its preference. Now say the text in the reread row delete question. Vim's support for regular is most powerful in many editors, and many advanced regular expressions are supported in VIM. Here's my solution:

:%s/\ (. *\) \n\1/\1\r/g
: g/^$/d

This requires two commands, and then Http://vim.wikia.com/wiki/Uniq_-_Removing_duplicate_lines found my enhanced version:

: g/^\ (. *\) $\n\1$/d
: g/\% (^\1$\n\) \@<=\ (. *\) $/d

Both of the preceding commands are similar to mine, which deletes the previous item of the duplicates, and the subsequent command deletes the contents of the duplicates. Note Two commands are independent and can be used separately. For the G command is not very familiar, it is a global command and will be fully introduced later.

Explanation of the second command:

g//d <–delete The lines matching the regexp
\@<= <–if the bit following matches, make sure the bit preceding this symbol directly precedes the match
\ (. *\) $ <–match The line into subst Register 1
\%( ) <-group without placing in a subst register.
^\1$\n <-match subst Register 1 followed by end of line and the new line between the 2 lines

Vim Delete duplicate rows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.