Hot answers tagged

190 votes

How do I use vim as a diff tool?

vim has this functionality built in (with the correct command line flag). vim -d <file1> <file2> This opens each file in a view and highlights the differences. Any code that is identical ...
  • 5,910
42 votes
Accepted

How to diff and merge two directories?

There is DirDiff.vim plugin to diff and merge two directories recursively. It performs a recursive diff on two directories and generate a diff "window". Based on that window you can perform ...
  • 16.9k
39 votes

How do I use vim as a diff tool?

If you are editing an open file and want to compare it to another file without closing the current one: Open the new file in split screen: For vertical split: :vs otherFile or horizontal split: :...
37 votes
Accepted

How do I customize vimdiff colors?

The colors are controlled by these four highlight groups (:help hl-DiffAdd): DiffAdd diff mode: Added line DiffChange diff mode: Changed line DiffDelete diff mode: Deleted line DiffText diff ...
35 votes
Accepted

Make panes resize when host window is resized

To go along with @janos's answer, you can set an autocmd to automatically press those keys when the window is resized (put this in your .vimrc without the leading colon if you want it to apply every ...
  • 13.9k
34 votes

How do I customize vimdiff colors?

One quick fix is to disable syntax highlighting. Sometimes the code syntax highlighting will cause the foreground text to be the same color as the vimdiff background color, making the text "invisible"....
  • 760
33 votes
Accepted

In Vimdiff, how do I switch the left and right panes?

You can use Ctrlw-x. From :he CTRL-W_x: CTRL-W x CTRL-W_x CTRL-W_CTRL-X CTRL-W CTRL-X Without count: Exchange current window with next one. If there ...
  • 24k
21 votes
Accepted

How to make the two windows equal width when comparing files?

You can equalize the size of windows with <c-w>=.
  • 328
20 votes
Accepted

Create mappings that only apply to diff mode

You can create an expression mapping that checks &diff. This is done using the <expr> keyword. Example nnoremap <expr> <C-J> &diff ? ']c' : '<C-W>j' With this, each ...
  • 7,290
20 votes
Accepted

Turn off synchronous scrolling not caused by either scrollbind or diff

As Christian Brabandt suggested in a comment, this can be caused by the 'cursorbind' setting. From :help 'cursorbind': When this option is set, as the cursor in the current window moves other ...
19 votes

vimdiff and merge conflicts

I normally use git on the command line. But when there is a merge conflict I use Vim to resolve them with (personally I do it with with the fugitive plugin). Note: fugitive is good for a lot of git ...
  • 5,910
18 votes
Accepted

Using Vimdiff to diff two things that are not local documents

You can diff two unwritten buffers: Open vim (or open a new tab in you current vim instance) Put your current code in one buffer or open an existing file (:e ./mySourceFile) Split your screen with :...
  • 46.8k
17 votes

More detailed comparison within a line

I don't think this can be done by Vim itself. From :h view-diffs (emphasis mine): hl-DiffText DiffText Changed text inside a Changed line. Vim finds the ...
  • 24k
16 votes

Make panes resize when host window is resized

Ctrlw= will resize the split panes to become equal. But I don't know how to make them equal automatically, triggered when the window is resized.
  • 2,658
16 votes
Accepted

Better diff color scheme

I quite like the diff colors in my colorscheme:
  • 33.3k
14 votes

In Vimdiff, how do I switch the left and right panes?

As you would switch any other window, <c-w>x or <c-w>r are two options. Having only two windows opended <c-w>k will switch them and leave the cursor in the window where it was ...
  • 4,522
14 votes

How do I customize vimdiff colors?

Extending Ingo Karkat's solution to terminal, hi DiffAdd ctermfg=NONE ctermbg=Green hi DiffChange ctermfg=NONE ctermbg=NONE hi DiffDelete ctermfg=LightBlue ctermbg=Red ...
  • 243
14 votes
Accepted

How do I differentiate between vim and vimdiff from within vimrc?

:help diff covers this: In your .vimrc file you could do something special when Vim was started in diff mode. You could use a construct like this: if &diff setup for diff mode ...
  • 28.9k
14 votes
Accepted

How do I enter into vimdiff mode given two splits are already open?

The command is called :diffthis. It must be executed in every window you want to add to the comparison. The inverse is :diffoff which exits diff mode in the current window. To exit diff mode in all ...
  • 17.9k
13 votes

Better diff color scheme

I have a syntax/diff.vim (that I source manually) with the following contents: hi DiffText cterm=none ctermfg=Black ctermbg=Red gui=none guifg=Black guibg=Red hi DiffChange cterm=none ctermfg=Black ...
  • 16.2k
12 votes

How do I differentiate between vim and vimdiff from within vimrc?

You can use the &diff option like in your vimrc: if &diff echo "in diff mode" else echo "not in diff mode" endif See :h 'diff'
  • 46.8k
11 votes

In Vimdiff, how do I switch the left and right panes?

I find the following commands much more intuitive than Ctrlw-x. :help CTRL-W_K The following commands can be used to change the window layout. For example, when there are two vertically split ...
10 votes
Accepted

Git mergetool vimdiff command

I used the trick from this SO question to see what the command line was, and got this: :exe '!tr "\0" " " </proc/' . getpid() . '/cmdline' :!tr "\0" " " </proc/23932/cmdline gvim -f -d -c ...
  • 24k
9 votes
Accepted

diffoff on all buffers

You can do this: :bufdo diffoff The :bufdo command runs a given command on all buffers. It works by cycling through all buffers and executing the command, so you will end up on the last buffer. ...
  • 7,290
8 votes
Accepted

VimDiff incorrectly showing all lines as changed

I think the most likely culprit is another buffer still in diff-mode. This can happen if you're looking at multiple diffs, one after another, and don't turn off diff-mode between diffs. Disable diff-...
  • 7,290
8 votes

How to make the two windows equal width when comparing files?

If you want the window widths to remain equal as you change the size of the Vim window, try this in your ~/.vimrc: if exists("##VimResized") if &diff au VimResized * wincmd = ...
  • 5,964
8 votes
Accepted

Is there a way to "take both" when using Vim as merge tool?

Not exactly what you asked, but may find this useful: Splice plugin: a Vim plugin for resolving conflicts during three-way merge. It has a nice demo screencast on Vimeo. If you are going to stick ...
  • 6,470
7 votes
Accepted

Navigate to first diff in diff mode on startup?

]c doesn't jump to the first difference, it jumps to the next difference. If your first difference is on the first line, ]c would jump to the the second one which is not what you want. One could work ...
  • 33.3k
7 votes
Accepted

How to split window directly from command line?

Vim's -o and -O options will open the files while splitting them horizontally or vertically respectively. Taken from Vim's help page :help -o and :help -O: *-o* -o[N] ...
  • 5,946
7 votes
Accepted

Modify vimdiff highlighting

You have a few questions, some explicit and some implicit. I'll try to answer them in order: What Do These Commands Do? You're running two commands: highlight DiffChange cterm=none ctermfg=fg ...
  • 1,173

Only top scored, non community-wiki answers of a minimum length are eligible