Vimdiff --- VIM comparison and merge tool, vimdiff --- vim merge
This article comes from the IBMDW http://www.ibm.com/developerworks/cn/linux/l-vimdiff/
Comparing and merging source program files (usually plain text files) has always been an important part of software development. Many powerful dedicated comparison and merge tools on the market, such as BeyondCompare. Many IDE or software configuration management systems, such as Eclipse, rational ClearCase provides built-in functions to support file comparison and merging.
When working remotely on Unix/Linux platforms, I am afraid that the simplest and ubiquitous is the command line tool, such as diff. Unfortunately, diff has limited functions and is not very convenient to use. As a command line comparison tool, we still hope to have a simple and clear interface, so that we can have a clear view of the comparison results; we also hope that we can quickly locate multiple differences and easily Merge files ....... The diff mode provided by Vim, usually called vimdiff, is such a powerful tool that can meet all these needs and even provide more powerful tools. In recent work, we have made a simple summary of the use of Vimdiff because we need to compare and merge a lot of files. Let's take a look at the basic use of vimdiff.
Start Method
First, ensure that the diff command in the system is available. The diff mode of Vim depends on the diff command. The basic usage of Vimdiff is:
# vimdiff FILE_LEFT FILE_RIGHT |
Or
# vim -d FILE_LEFT FILE_RIGHT |
Figure 1 shows the execution result of the vimdiff command.
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:
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:
You can use shortcuts to quickly move between different points. Jump to the next difference:
The reverse jump is:
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:
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:
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:
If you want to cancel the modification, you can directly
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:
If you want to save all files:
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:
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:
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:
Is to set the context to 3 rows and expand the vimdiff screen with some of the same text:
Conclusion
Vimdiff is the best choice when you cannot use graphical comparison tools or when you need to quickly compare and merge a small number of files.
How to compare and merge documents in WORD?
Will F1? The following is an excerpt from WORD2002 help. I. Microsoft Word displays the difference in revision when comparing any two documents using the comparison and Merge function. The comment box displays the inserted or deleted content, format changes, and comments. 1. collaborative processing documentation if multiple reviewers return revisions and comments to different copies of the original document, you can merge all revisions they have made into a separate document, review each revision from this document. After you submit the document for review, you can edit it. Word displays the added content and revisions made by the reviewer. It is recommended that the reviewer enable the revision function to edit the document (click the Tools menu and point to revision to set the revision function), but if this function is not enabled, word detects and displays the revision. 2. Select the position of the displayed result and select the document to be compared (target document). You can select one of the three positions to display the Merged Results. Merge revision into target document to merge revision from target document to new document to merge current document and target document to a new document. when the "valid black lines" option is used in a valid black line comparison document (this option can be displayed by clicking "compare and merge documents" on the "Tools" menu ), word compares the document and only displays the changed parts between the two documents. That is, previous revisions to the document are not displayed as revisions. Before displaying document differences, Word accepts previous revisions in advance. No changes were made to the compared document. This type of comparison is usually displayed in the third document created. Note: If you want to compare the revisions made by different reviewers, do not select this option. Instead, use the merge command. 2. Compare and merge the edited documents. On the Tools menu, click Compare and merge documents ". Select the original document, click the arrow next to merge, and then Perform one of the following operations: to display the comparison results in the original document, click merge ". To display the results in the currently opened document, click "merge to current document ". To display the results in the new document, click "merge to new document ". Note: To ensure the best merging effect, you should ensure that the "options" dialog box is displayed (click "options" in the "Tools" menu ") on the "Security" tab of, select the "store random numbers for enhanced merging accuracy" check box. If you have used the "version" command in the "file" menu to save multiple versions of a document in one file and want to compare the current version with the earlier version, use different names to save earlier versions as independent files. 3. Merge the revisions and comments of multiple reviewers into one document to open the document to which the revisions will be merged. On the Tools menu, click Compare and merge documents ". Open a document containing the revisions to be merged. Click the arrow next to merge and then click merge to current document ". Repeat steps 2 to 4 until all copies of the document are merged. Note: To optimize the merging of multiple reviewers, click "options" in the "Tools" menu, and then confirm to select the "store random numbers for enhanced merging accuracy" check box. Microsoft Word can save a set of format changes at a time. Therefore, when you merge multiple documents, the system prompts you whether to retain the format of the original document or use the format of the currently edited document. If you do not need to track revision tags, clear the "Search format" check box in the "compare and merge documents" dialog box.
EXCEL multi-Table merge and summary tool (large data volume)
Download an easy-to-use excel app, free gadgets, and use the combined workbook function to meet your requirements.