Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight only the actual differences in Vim diff?

Tags:

vim

diff

vimdiff

When using vimdiff, it highlights the differing portion of the lines in a "greedy" fashion. That is, when comparing two lines:

Left window: This one is his home

Right window: That one is her home

then the whole line is colored pink, but on the left, is one is his and on the right at one is her parts are highlighted in red, as a mismatch:

This one is his home
That one is her home

How can I make vimdiff only highlight the actual differences?

This one is his home
That one is her home

like image 499
ysap Avatar asked Jul 22 '17 15:07

ysap


2 Answers

Please visit https://github.com/rickhowe/diffchar.vim instead of https://github.com/vim-scripts/diffchar.vim. Thank you.

like image 71
Rick Howe Avatar answered Oct 26 '22 13:10

Rick Howe


There is nothing built-in in vim to achieve this but you can use diffchar.vim to achieve this.

After installing plugin, vimdiff will give you character wise diff. You can toggle between this mode and normal diff using F7 key

From plugin Readme:

For example, in diff mode: ([DiffText], )

(file A) The [quick brown fox jumps over the lazy] dog. 
(file B) The [lazy fox jumps over the quick brown] dog. 

this plugin will exactly highlight the changed and added units:

(file A) The [quick] <brown >fox jumps over the [lazy] dog. 
(file B) The [lazy] fox jumps over the [quick] <brown >dog. 
like image 28
sudo bangbang Avatar answered Oct 26 '22 13:10

sudo bangbang