Using Vim as a diff tool
Firstly I will start with why to not use diff
. I am not suggesting a replacement, I have simply found that Vim offers a much better interface, that is available on most (*nix based) server environments for comparing and merging files side by side.
Getting started
vim -d file_original.txt file_new.txt
Your tool of choice here is vim -d
, so if you like this as a ‘patch’ to diff
, why not be naughty and alias it? I have aliased alias diff='vim -d'
in my shell preferences.
Getting fancy
Wow, i can see the difference between 2 files, big deal! Try adding more files to the arguments, suddenly we have loads more power to compare multiple files, easily.
vim -d file_original.txt file_new.txt file_new_ammendments.txt
Commands
ctrl+ww
– will let you navigate buffers.
When comparing just 2 files, these commands will be handy when you select the lines to merge
dp
– diff putdo
– diff obtain/get
If you are in multi diff mode, these may be handy as you need to write long hand commands;
:diffget 3
If you were in buffer 1, writing this command would obtain the difference in buffer 3:diffpu 1
Again, write this in buffer 3 and it will place the change in buffer 1
Writing/saving changes
:wqall
Further Reading
- http://www.vim.org/htmldoc/diff.html
- http://en.wikipedia.org/wiki/Diff
Post your comment