Vimdiff and VIM split

Source: Internet
Author: User

See:

Http://blog.csdn.net/swust_long/article/details/6990033

Http://www.ibm.com/developerworks/cn/linux/l-vimdiff/

The simplest command to open a new window is: Split

Close Window: close, or: Quit or ZZ. However, close can avoid accidental exit of VIM when the next window is left.

Close all Windows except the current window: only

Vsplit

Vnew

The basic usage of vimdiff is:

# Vimdiff file_left file_right
Or
# Vim-D file_left file_right

We can see a clear comparison result. The screen is vertically split, and the two files to be compared are displayed on both sides of the screen. The same row in the two files is folded consecutively so that the user can focus on the differences between the two files. Only the background color of the row in a file is set to blue, and the corresponding position in the other file is displayed as green. The two files exist, but the lines that contain the difference are displayed as pink backgrounds. The text that causes the difference is highlighted in red background.
In addition to using this method to start the diff mode of VIM, we can also use the split window command to start the diff mode:
# Vim file_left
Then input:
: Vertical diffsplit file_right
The same effect can be achieved. If you want to switch the positions of two windows, or you want to change the window separation method, you can use the following command:
1. CTRL-w k (Move the current window to the top)
2. CTRL-w h (Move the current window to the leftmost)
3. CTRL-w j (Move the current window to the bottom)
4. CTRL-w l (Move the current window to the rightmost)
The Operations 1 and 3 change the window to the horizontal split mode.

Move cursor

Next, move the cursor between lines to see that the screen scrolling between the left and right sides is synchronized. This is because the "scrollbind" option is set. Vim tries its best to ensure file alignment on both sides. If you do not want this feature, you can set it:
: Set noscrollbind
You can use shortcuts to quickly move between different points. Jump to the next difference:
] C
The reverse jump is:
[C
If you add a number before the command, you can skip one or more differences to jump farther. For example, if "2] C" is entered in the row at the first variance point, the next variance point is crossed and the third variance point is jumped.

File Merging

One of the final purposes of file comparison is to merge to eliminate the differences. If you want to copy the content of the current file from one differential point to another, you can run the following command:
DP (diff "put ")
To copy the content of another file to the current line, run the following command:
Do (diff "get", because DG is occupied by another command)
If you want to manually modify a row, you can use the usual Vim operation. If you want to jump back and forth between two files, you can use the following command sequence:
CTRL-W, W
After modifying one or two files, vimdiff tries to automatically recompare the files to reflect the comparison results in real time. However, there will also be situations where the processing fails. In this case, you need to manually refresh the comparison results:
: Diffupdate
If you want to cancel the modification, you can directly
<ESC>, u
However, be sure to move the cursor to the file window where you want to undo the modification.

Operate two files simultaneously

After the comparison and merge come to an end, you can use the following command to operate the two files simultaneously. For example, exit simultaneously:
: QA (quit all)
If you want to save all files:
: Wa (write all)
Or the merge command of the two, save all the files, and then exit:
: Wqa (write, then quit all)
If you do not want to save any operation results when exiting:
: QA! (Force to quit all)

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 modify the default number of contextual lines, 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, the reason why it uses the Z letter is because it looks like a folded paper)
Then, you can use the following command to fold again:
ZC (folding close)

The automatic LINE folding is set wrap, so that the characters that exceed the screen width are displayed in the next line.

Textwidth sets the maximum width of a row, and the part exceeding the limit is automatically added to the next row. If it is set to 0, this effect will not be achieved. This line feed will add a \ n at the end of the line, so if the content in the printf quotation marks is too long, it will be a problem.

What makes me confused is that wrapmargin indicates that wrap is a line break, that is, the rows exceeding the screen width will automatically rewound and continue in the next line, but there is no \ n in the middle, that is, it is essentially a row rather than two rows. This WM should first feel the width of the loop, that is, to return to a specified width rather than line feed, even if you still have a lot of screen width. However, the actual effect is not the case. If WM is set to 80, it seems to have a line break in more than 70 places. Note that it is a line break rather than a line break. Then I finally found a detailed description of this ......
The 'wrapmargin 'option does almost the same. the difference is that 'textwidth 'has a fixed width while 'rapmargin' depends on the width of the screen. when using 'wrapmargin 'This is equal to using 'textwidth' with a value equal to (columns-'wrapmargin '),
Where columns is the width of
Screen.
That is, it sets the width of the white space on the right of the screen, that is, the size of the literal margin, and the actual effect is still broken. Because the width after my gnome-terminal full screen is 153, WM = 80 is equivalent to Tw = 153-80 = 73, so there is the above phenomenon, clear this, then I will directly set the TW parameter ...... It's been an afternoon.

You can also set formatoptions. The default value is fo = TCQ. For more information, see help fo-Table. Here are some parameters you have added:
The fo + = Ro parameters are automatically added to the comment leader.
R automatically Insert the current Comment leader after hitting
<Enter> in insert mode.
Fo + = mm is related to width characters and has not been tested.
M also break at a multi-byte character above 255. This is useful
Asian text where every character is a word on its own.
M when joining lines, don't insert a space before or after a multi-byte
Character. overrules the 'B' flag.

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.