Wiki

by yszheda

View project onGitHub

My Vimdiff Tips

Enter Diff Mode

External

$ vimdiff <left-file> <right-file>
# or
$ vim -d <left-file> <right-file>

read-only way:

$ viewdiff <file1> <file2>

split vertically (default):

$ vimdiff -O <file1> <file2>

split horizontally:

$ vimdiff -o <file1> <file2>

Internal

Assume currently you have executed:

$ vim <left-file>

Then you can open vimdiff in the ex mode of vi:

  • split vertically:
    :vert[ical] diffsplit <right-file>
    
  • split horizontally:
    :diffsplit <right-file>
    

Jump

Next different position: ]c Previous different position: [c Scrolling setting:

:set noscrollbind

Merge

  • diff put:
    dp
    
    :diffpu[t]
    
  • diff obtain
    do
    
    :diffg[et]
    
  • update diff status:
    :diffupdate
    

Miscellaneous Usage

Compare the output of two commands: using anonymous pipes (supported by bash and zsh).

e.g. Binary Diffs from Editing Binary Files with Vim:

$ vimdiff <(xxd bin_file_1) <(xxd bin_file_2)