How to use vimdiff

Vim can be used as a diff and merge tool. While it cannot match the beauty and power of GUI programs like Meld, it is immensely useful to diff and merge over a SSH session.

  • Vim can be invoked in diff mode either using vim -d or as vimdiff. Just pass in the names of the files to compare:
$ vimdiff 1.cpp 2.cpp
$ vim -d 1.cpp 2.cpp 3.cpp
  • Vim in diff mode displays each file in its own window side-by-side showing the diff sections in colors. You can switch between the windows using the normal Vim commands. (I use Ctrl-W-W.) And when you scroll down all the windows scroll down with you because they are locked to each other.

  • To switch to and fro between diffs use the ]-c and [-c commands.

  • To put the diff the cursor is resting on to the next window use the command dp

  • To pull the diff from the next window use the command do

Tried with: Vim 7.4 and Ubuntu 16.04

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.