vim diff

37 views
Skip to first unread message

rudy b

unread,
Aug 23, 2010, 10:31:06 PM8/23/10
to vim_use
Hi,
I have a question about "diff".
I've always found "diff" very powerful, and I've never had any issue
with this commad.
Expect that I encoutered a problem, that I wish "diff" would be just
slightly more flexible.

Usually "diff" is very smart in aligning the lines in a way to
optimise its match.
Is there any way that I can set some sort of flag for the "diff"
command to start comparing the files line by line ONLY (and not try to
use any of its smart matching algorithms) ?
line#1 (file1) .... line#1 (file2)
line#2 (file1) .... line#2 (file2)
line#3 (file1) .... line#3 (file2)
...
line#n (file1) .... line#n (file2)

thanks in advance,
Rudy

Andy Wokula

unread,
Oct 2, 2010, 10:57:28 AM10/2/10
to vim...@googlegroups.com

This kind of diff can be done in Vimscript, see attached plugin! It's
simple yet, for example 'diffopt' is ignored.

Usage:

:SetLineByLineDiff
enable line-by-line diff (set 'diffexpr' to a different value)

:SetLineByLineDiff!
disable, set 'diffexpr' back to the default

--
Andy

diffbyline.vim

Sammi

unread,
Oct 3, 2010, 11:49:54 AM10/3/10
to vim_use
Do I need open two files in vim or use vimdiff command?
>  diffbyline.vim
> 3KViewDownload

Andy Wokula

unread,
Oct 4, 2010, 1:37:24 PM10/4/10
to vim...@googlegroups.com
Am 03.10.2010 17:49, schrieb Sammi:
> Do I need open two files in vim or use vimdiff command?

You should drop diffbyline.vim into your plugin folder to make the
DiffLineByLine() function available after startup.

Within Vim, execute
:SetLineByLineDiff

which is a shortcut for :set diffexpr=DiffLineByLine()
but more verbose (and easier to type, as command names can be completed
with <Tab>).

The next diffing procedure will then use the new diff method, for
example:
:diffthis
:wincmd w
:diffthis
or
:diffsplit {filename}


Using vimdiff:
vimdiff +SetLineByLineDiff {file1} {file2}
vim -d +SetLineByLineDiff {file1} {file2}

SetLineByLineDiff is a little too verbose here ...
With appropriate quoting you can use (example for Windows):
vimdiff +"set diffexpr=DiffLineByLine()" {file1} {file2}

--
Andy

Reply all
Reply to author
Forward
0 new messages