47
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:
:...
45
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"....
43
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 ...
23
votes
Accepted
How to make the two windows equal width when comparing files?
You can equalize the size of windows with <c-w>=.
23
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
...
23
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 :...
22
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 ...
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 ...
Community wiki
16
votes
Accepted
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
...
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 ...
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'
10
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.
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 =
...
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 ...
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 ...
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 ...
7
votes
Accepted
Overwrite colorscheme syntax highlighting
DiffAdd and DiffDelete are only used when actually performing a diff ($ vim -d foo.txt bar.txt, $ vimdiff foo.txt bar.txt, $ git mergetool, etc.); those highlight groups are totally irrelevant, here.
...
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 ...
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 ...
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 ...
6
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 $'...
6
votes
Better diff color scheme
My own scheme "Traffic light colors" featuring red, yellow, green and blue.
They are a bit gentler in GVim than on the terminal.
But they were really designed to be intuitive (for westerners) rather ...
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 ...
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 ...
6
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 ...
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 ...
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 ...
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: $(...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vimdiff × 118git × 16
split × 6
merge × 6
vimrc × 5
vimscript × 5
autocmd × 5
colorscheme × 5
syntax-highlighting × 4
highlight × 4
key-bindings × 3
neovim × 3
buffers × 3
vim-windows × 3
microsoft-windows × 3
scrolling × 3
undo-redo × 3
search × 2
command-line × 2
cursor-movement × 2
external-command × 2
folding × 2
netrw × 2
encoding × 2
plugin-fugitive × 2