how to display only exact differences in vim diff mode

882 views
Skip to first unread message

WU Zhaojun

unread,
Mar 13, 2008, 2:14:53 AM3/13/08
to vim...@googlegroups.com
Hi all,

I want to know if there is a solution to display the
differences in *word based* way between two
files in *vim diff* mode. Since by default,

"Vim finds the first character that is different, and
the last character that is different (searching from
the end of the line). The text in between is highlighted.
This means that parts in the middle that are still the
same are highlighted anyway. " (extracted from diff.txt)

What I want, however, is: for example, given 2 files:

file 1 contains just one line:

"hello world"

file 2 contains the other line with two new words at the
beginning and the end:

"diff1 hello world diff2"

I want VIM to just highlight the word "diff1" and the word
"diff2" in file 2, instead of the whole line.

Is it possible?

Thanks!
--
Best,
Zhaojun (Joseph)

Richard Hartmann

unread,
Mar 13, 2008, 6:24:10 AM3/13/08
to vim...@googlegroups.com
On Thu, Mar 13, 2008 at 7:14 AM, WU Zhaojun <wuzh...@gmail.com> wrote:

> I want to know if there is a solution to display the
> differences in *word based* way between two
> files in *vim diff* mode. Since by default,

That would be very useful, especially if one could define
what seperates 'words' form each other.


Richard

Benjamin Fritz

unread,
Mar 13, 2008, 10:17:19 AM3/13/08
to vim...@googlegroups.com

You could try messing with the highlight groups for the diff highlighting.

For your purposes, you could try:

hi DiffChange guibg=white
hi DiffText guibg=red

(This assumes you are using gvim, and that your background is normally
set to white)

See :help hl-DiffAdd, :help hl-DiffChange, :help hl-DiffDelete, and
:help hl-DiffText for details.

Note that this will actually be "character" based, not "word" based.

WU Zhaojun

unread,
Mar 14, 2008, 1:59:32 AM3/14/08
to vim...@googlegroups.com
Hi, Benjamin,

> You could try messing with the highlight groups for the diff highlighting.
>
> For your purposes, you could try:
>
> hi DiffChange guibg=white
> hi DiffText guibg=red

I tried this. But saddly it is not the solution in my case.
As I mentioned, given a similar line in two files:

"hello world"

and,

"diff1 hello world diff2"

I want vimdiff just highlighting "diff1" and "diff2" in the
second file, excluding the "hello world" part. However,
your solution will still highlight the whole line, as vim
highlights everything between two differences in the
line by default.

Thanks,
Zhaojun (Joseph)

Reply all
Reply to author
Forward
0 new messages