Vim: Find Visual Difference using diffsplit


Many a times you want to compare two different files… Unless you have a good utility… you cant. But for Vim as its a wonderful tool, get a good visual difference.

vim-diff.png

Let us consider you have two files js1.js and js2.js

js1.js

javascript:
var selection;
var s;
if (window.getSelection)
{
selection = window.getSelection();
} else if (document.getSelection)
{
selection = document.getSelection();
}
if (selection.toString().length > 0)
{
s = selection.toString();
} else {
s = prompt("Search", "Martina Hingis");
}
if (s.length > 0)
{
window.location = "http://en.wikipedia.org/wiki/"+s;
}

js2.js

javascript:
var selectionR;
var s;
if (window.getselectionR)
{
selectionR = window.getselectionR();
}
if (selectionR.toString().length > 0)
{
s = selectionR.toString();
} else {
s = prompt("Search", "Martina Hingis");
}
if (s.length > 0)
{
window.location = "http://en.wikipedia.org/wiki/"+s;
}

Now we've got to compare these two files..

  • Open any file say js1.js in vi
  • Use the following command to split the difference
    vert diffsplit js2.js
  • The command vert (or can be vertical) will tell that the differential split of js2.js with the current file i.e. js1.js is to be shown vertically.

Lovely isn't it.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


%d bloggers like this: