Using Vim to compare the contents of two files

Source: Internet
Author: User
Tags diff

Ext.: http://blog.chinaunix.net/uid-22548820-id-3477464.html

1. Use the VIM comparison mode to open two files:
vim-d file1 file2
Or
Vimdiff file1 file2

2. If you have already opened the file File1, then open another file file2 to compare:
: Vert diffsplit File2
If you do not use the vert command, the diffsplit will be divided up and down two windows.

3. If you have opened two file File1,file2 with split mode, you want to compare the two files differently.
Enter the commands in each of the two windows:
:d Iffthis

4. If you change the contents of a window, VIM does not automatically update the diff check, you can update it with the following command:
:d iffupdate

5. Navigate to a different point:
[C jumps to the previous point of difference
]c jump to a different point

6. Jump between windows:
Ctrl-w W jumps to the next window
Ctrl-w h jumps to the left window
Ctrl-w L jump to the right window
Ctrl-w J jump to the window below
Ctrl-w K jumps to the top window

7. Merging documents:
DP applies the current document content of the difference point to another document (diff put)
Do copy the contents of another document of the difference point to the current document (diff get)

8. Expanding and viewing the context
When comparing and merging files, it is often necessary to combine the context to determine the final action to take. Vimdiff default is the difference between the 6 lines of text will be displayed for reference. The other lines of the same text are automatically collapsed. If you want to modify the default number of context rows to 3 rows, you can set this:
: Set Diffopt=context:3

ZF creates a collapse (using numbers to create a fold that has the current line to the next number of rows, such as 3j to create a fold that includes 4 rows)
Zo Open fold (L can also open folding)
ZC Close Current collapse
ZM Close all folds
ZR Open All folds
ZE Delete all collapsed
ZD Delete the current collapse
Za If the current open is closed, if it is currently closed open
ZJ to the beginning of the next fold
ZK to the end of the previous fold

Using Vim to compare the contents of two files

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.