Vimdiff is a tool that comes bundled with Vim and its a wonderful tool for comparing code and merging changes. Vimdiff starts Vim on two (or three) files. Each file gets its own window. The differences between the files are highlighted. This is a nice way to inspect changes and to move changes from one version to another version of the same file.
vimdiff [options] file1 file2 [file3]
You may also use “gvimdiff” or “vim -g”. The GUI is started then.You may also use “viewdiff” or “gviewdiff”. Vim starts in readonly mode then.”r” may be prepended for restricted mode
If you want to open files use the following command
vimdiff file1 file2
vim -d file1 file2
If you want to open vertical splits for your files use the following command
vimdiff -O file1 file2
If you want to open horizontal splits for your files use the following command
vimdiff -o file1 file2
If you want to open files in particular directory, use the following command.
Vim first append the file name of the first argument to the directory name to find the file.
vimdiff file1 file2 [file3 [file4]]
vim -d file1 file2 [file3 [file4]]
do – Get changes from other window into the current window.
dp – Put the changes from current window into the other window.
]c – Jump to the next change.
[c – Jump to the previous change.
Ctrl W + Ctrl W – Switch to the other split window.
To ignore whitespace use this command: set diffopt+=iwhite
To turn that back off use: set diffopt-=iwhite
Remote editing using vim
$ vimdiff scp://example.com//path/to/remote/file /path/to/local/file