Skip to main content Skip to navigation

2b.9 Advanced features

Comparing files

vim has a nice feature of comparing two files. For example, if you have two different versions of a text file and you want to know which lines have changed, you can type in the shell command:

vimdiff file1.txt file2.txt

This willl start up vim in 'difference' mode. It will open two windows. The first file file1.txt will be in the left and the second file file2.txt in the right window. Any differences between the two files are highlighted.

To switch between windows use the keystroke CTRL+w w . You can make changes to the file in the active window. For example, if you want to remove the current line and instead use the line of the other file, type in do (from delete, other). In this way it is easy to undo some changes that you have made in a newer version of a file.