Use Vim to compare the content of the two files

Source: Internet
Author: User

1. Use Vim's comparison mode to open two files:
Vim-D file1 file2
Or
Vimdiff file1 file2

2. If the file file1 has been opened, open another file file2 for comparison:
: Vert diffsplit file2
If the vert command is not used, diffsplit will split up and down two windows.

3. If you have opened two files, file1 and file2, in Split mode, and want to compare the differences between the two files.
Enter the following commands in two windows:
: Diffthis

4. If the content of a window is changed and VIM does not automatically update the diff check, run the following command to update the window:
: Diffupdate

5. Locate the differences:
[C jump to the previous difference
] C jump to the next difference

6. jump between Windows:
CTRL-w jump to the next window
CTRL-w h jump to the Left window
CTRL-w l jump to the right window
CTRL-w j jump to the window below
CTRL-w k jump to the window above

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

8. Expand and view the context
When comparing and merging files, you often need to combine context to determine the final action to be taken. By default, vimdiff displays the texts of 6 rows in the upper and lower directions for your reference. Other text lines are automatically folded. If you want to change the default number of contextual lines to three, you can set it as follows:
: Set diffopt = context: 3

You can use a simple collapse command to temporarily expand the same collapsed text line:
Zo (folding open, Z looks like folding paper)

Then, you can use the following command to fold again:
ZC (folding close)

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.