Skip to main content
Share Your Experience: Take the 2024 Developer Survey
50 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: :...
brother-bilo's user avatar
49 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"....
wisbucky's user avatar
  • 950
45 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 ...
Ingo Karkat's user avatar
  • 17.9k
26 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 :...
statox's user avatar
  • 50.1k
25 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 ...
kmario23's user avatar
  • 353
25 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 ...
Matt's user avatar
  • 20.8k
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 ...
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 ...
Rich's user avatar
  • 32.1k
13 votes

How do I customize vimdiff colors?

Another quick (perhaps even lazy) fix is to just do something like: :colo desert This will change your color scheme, and in some cases will make hidden text become visible.
Nathan Chappell's user avatar
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'
statox's user avatar
  • 50.1k
8 votes

Using vim diff to compare the working directory to the HEAD in git?

To view unstaged modifications to your git working tree in vimdiff, try: git difftool --tool=vimdiff or for staged changes git difftool --tool=vimdiff [ --staged | --cached ] These commands are ...
the_velour_fog's user avatar
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 ...
mMontu's user avatar
  • 6,650
7 votes

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

yank and put can work without any plugins or extra functions, though it is, perhaps, a bit less convenient than do or dp Just copy the needed bits from the parent buffers and paste them into the ...
8bittree's user avatar
  • 1,536
7 votes

How do I use Vim as a diff tool?

For NeoVim, you can setup your ~/.gitconfig with the following commands git config --global merge.tool nvim git config --global mergetool.keepBackup false git config --global mergetool.nvim.cmd $'...
run_the_race's user avatar
7 votes

How to diff and merge two directories?

If you just want to just use vimdiff without installing anything extra, the following command will open all the differing files in succession letting you look at the changes with vimdiff: for ...
Jongab's user avatar
  • 71
7 votes
Accepted

Make vim switch to other window after opening a diff

You could add this to your .vimrc: command! -nargs=1 -complete=file Diffsplit diffsplit <args> | wincmd p This create a Diffsplit command (note the capitalized D) which takes one argument and ...
statox's user avatar
  • 50.1k
7 votes

How can I determine if *any* window in the current tabpage is in diff-mode?

You can sum up the values of &diff for each window, and see if the total is > 0: let any_diff = 0 windo let any_diff += &diff echo any_diff . ' windows in diff mode' if any_diff > 0 | do ...
muru's user avatar
  • 25k
7 votes
Accepted

IDE-like inline diff highlighting in Vim

You can do this with the vim-gitgutter plugin. If you're not using git, then Signify has a similar feature. After installing vim-gitgutter, you can switch the highlighting on and off with the ...
Rich's user avatar
  • 32.1k
6 votes
Accepted

Stop vim from removing whitespace on save for diff files

Since there was nothing explicit in my .vimrc that acted on only-whitespace lines and the diff syntax file did no such thing either, this had to with my plugins somehow. I find out that I had an ...
oligofren's user avatar
  • 1,103
6 votes

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

To combine changes from both the target and merge branches in a single command: You can just delete the lines with Git conflict markers. The following two methods will delete all lines that start with:...
user3751385's user avatar
6 votes
Accepted

vimdiff two files, one ro the other rw

You can use startup commands to do this. From :h -c +{command} *-+c* *-c* -c {command} {command} will be executed after the first file has been read (and after ...
DJMcMayhem's user avatar
  • 17.7k
6 votes
Accepted

If one can diff from Vim without the need to boot `vimdiff` then why is it a binary program?

vimdiff as well as the other binaries are just symbolic links to the actual vim binary. This is done because when vim starts up it checks under which name it has been started and does perform some ...
Christian Brabandt's user avatar
6 votes
Accepted

Turn syntax off only for current buffer/window?

Buffers and windows are different things. To clear syntax for a particular buffer you can set the syntax option to empty string (or even simply do :syntax clear which should be the same for most ...
Matt's user avatar
  • 20.8k
5 votes

Get a vimdiff view of changes made by a patch / diff file

Use: vim <file> +"vertical diffpatch <patch-file>" Note the warning from :help inside this this script I call vimdiffpatch: #!/bin/bash if [[ $# -ne 2 ]]; then echo "Usage: $(...
Tom Hale's user avatar
  • 2,711
5 votes

How do I use Vim as a diff tool?

You can place below mentioned setting in .gitconfig file found in %homepath% (or %userprofile%) directory of the currently logged in user: [diff] tool = vimdiff This will enable git bash tool to ...
RBT's user avatar
  • 151
5 votes
Accepted

Automatically disable cursorline when in diff mode?

One would expect, that the OptionSet autocommand is triggered when entering diff mode. Unfortunately that is currently not the case. So I created a patch that will enable this behavior. Once it is ...
Christian Brabandt's user avatar
5 votes

How can I determine if *any* window in the current tabpage is in diff-mode?

I don't like using windo that could trigger events if done without any caution, and thus I prefer using programmatic ways instead. For instance, we can obtain the window numbers of the windows in ...
Luc Hermitte's user avatar
  • 17.4k
5 votes
Accepted

`vimdiff` nor `nvim -d` are working as an external diff tool for git

I tried git config --global diff.tool vimdiff3 git config --global difftool.vimdiff3.path nvim git config --global merge.tool vimdiff3 git config --global mergetool.vimdiff3.path It worked like a ...
Pie's user avatar
  • 175
5 votes
Accepted

Any difference between vimdiff and vim -d?

If your vim supports diff mode (which is in most cases), there is no difference. There is a minor difference though, if your vim is compiled without the +diff feature, vimdiff a b will produce the ...
Mass's user avatar
  • 14.1k
4 votes

Make vim switch to other window after opening a diff

Here you can find the source code defining the diffsplit command: vim/vim, let see what it does: It set some reference to the old window, as we will create a new one. It disable the tab opening Split ...
nobe4's user avatar
  • 16.1k

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