How to compare contents of two or more files in Linux with vimdiff

For comparing the contents of two (three or four) files in Linux I’m using one tool named vimdiff. To get this program you need to install vim-enhanced package, but if you already have vim installed on your system you already have this package…

# To install it on CentOS run
yum install vim-enhanced
# Or (why not).
yum install vim

To compare two files with vimdiff, you can run simple vimdiff and put files which you want to compare. In this case we will compare two files but you can use tool to compare up to 4 different files.

vimdiff file1.txt file2.txt

Here are views of two files compared using this method. For testing, I’ve just modified one line from file2.txt.

As you can see, differ text is (Kompjuteras diff here) and it’s marked red. If you want to modify some of this two files, you can jump between this two screens with CTRL+w+w (CONTROL button and press w twice).

When you want to exit from this window(s) you can do that with simple vim commands: q! for first window and again :q! for a second….or if you want to exit from both windows in the same time you can use :qa!

More about vim commands you can find in man pages of vim (just run: man vim)