Professional Documents
Culture Documents
Vim Quick Tutorial
Vim Quick Tutorial
Vim Quick Tutorial
I recently started using exclusively Vim (and gVim) for my coding needs. Vimdiff is a tool that comes bundled
with Vim and its a wonderful tool for comparing code and merging changes. If you'd prefer to use a non-Vim
based diff tool, checkout visual diff tools in linux [http://amjith.blogspot.com/2007/07/visual-diff-tools-in-linux.html]
for more variety.
[http://3.bp.blogspot.com/_Klq-3NKFe2s/SMfeDZ9gY9I/AAAAAAAAAaA/zHwt-XJqt0M/s1600-h/vimdiff.png]
Keyboard Shortcuts:
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.
Update: Allan [http://www.blogger.com/profile/06760506313601452399] commented these two tips that I
personally use quite often.
If you load up two files in splits (:vs or :sp), you can do :diffthis on each window and achieve a diff of files
that were already loaded in buffers
:diffoff can be used to turn off the diff mode.
Posted 28th August 2008 by Amjith Ramanujam
Labels: vim
24
View comments
Casey 12:01 PM
http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html
1/5
12/7/2013
mkoga 6:43 PM
Very cool, thanks for the tip!
Reply
yungchin 10:29 AM
Thanks! Just what I was looking for.
Reply
angel 1:38 AM
thanks a loads.... :) Jai ho!!
Reply
Anonymous 4:56 PM
Thanks for the great tip
Reply
peerlessdeepak 6:27 AM
http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html
2/5
12/7/2013
Anonymous 8:15 AM
To ignore whitespace use this command: set diffopt+=iwhite
To turn that back off use: set diffopt-=iwhite
Reply
bothie 6:36 AM
The only thing missing in this tutorial: How can I undo a dp/do command?
Reply
Replies
Divye Kapoor 1:23 PM
+1 if you have a tip here.
Anonymous 12:03 PM
After typing 'u', type ':e %' to get the coloring back.
Reply
~rAGU 1:38 PM
do command is bit tricky. Esc and then type do placing the cursor at the beginning of the diff and place
cursor at the end then type do again to bring the change from the other window.
+ can be expanded by pressing -> key to see text where there is no diff. Asusual :x saves and exits.
Reply
Martin 4:10 AM
Hi, this is nice, but I had to figure out how to get it into diff mode in first place. Might be nice, if you could
add that here.
And somehow it is not very clever, I have two lines, both starting off the same and then ending in differntly.
Still, it tells me the whole line in red color, like it were different.
Reply
Anonymous 11:38 AM
http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html
3/5
12/7/2013
@bothie: just do 'u' in the affected window to undo the editing command, as usual in vim
Reply
Deepak 12:42 AM
This tip is very useful.. I started using vimdiff and enjoying.
Reply
Allan 2:14 PM
Yet another tip to help people out... if you load up two files in splits (:vs or :sp), you can do :diffthis on each
window and achieve a diff of files that were already loaded in buffers. I usually end up doing it this way
because I already have the two versions loaded side by side.
Another tip to quit diffing a split is to use :diffoff. I remember this one by telling diff to f-off. :P
Reply
Amjith 2:22 PM
Thanks Allan:
I've updated the post to reflect your tips. :)
Reply
shb 2:31 PM
I was just looking for it! :)
After a minute I also needed :diffupdate
Reply
http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html
4/5
12/7/2013
Enteryourcomment...
Commentas:
GoogleAccount
Publish
Preview
http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html
5/5