VimDIFF - ONLY on the first field of two files ?

26 views
Skip to first unread message

Philip Rhoades

unread,
Apr 1, 2021, 8:08:34 AM4/1/21
to Vim Users
People,

I live in vim and therefore use vimdiff most of the time for my needs
but I have a use case where I only want to diff on the FIRST field of
two files ie the files have lines that look like:

[dir|file]name | [D|F] | mtime

and I need to be able to have vimdiff only working on the [dir|file]name
and ignore the rest of the line - is this possible somehow?

Thanks,

Phil.
--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: ph...@pricom.com.au

Bram Moolenaar

unread,
Apr 1, 2021, 12:48:16 PM4/1/21
to vim...@googlegroups.com

Philip Rhoades wrote:

> I live in vim and therefore use vimdiff most of the time for my needs
> but I have a use case where I only want to diff on the FIRST field of
> two files ie the files have lines that look like:
>
> [dir|file]name | [D|F] | mtime
>
> and I need to be able to have vimdiff only working on the [dir|file]name
> and ignore the rest of the line - is this possible somehow?

This is currently not possible. And it would be more than a bit of work
to implement. At the same time, it can be very useful to be able to
diff while ignoring some text.

A first idea would be to define a pattern, replace the matched text with
spaces, create the diff, then undo the replacement. Perhaps also
highlight the ignored text. Optionally this would work the other way:
replace the not-matched text with spaces.


--
Latest survey shows that 3 out of 4 people make up 75% of the
world's population.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Charles Campbell

unread,
Apr 1, 2021, 12:58:12 PM4/1/21
to 'Philip Rhoades' via vim_use, vim...@googlegroups.com
'Philip Rhoades' via vim_use wrote:
> People,
>
> I live in vim and therefore use vimdiff most of the time for my needs
> but I have a use case where I only want to diff on the FIRST field of
> two files ie the files have lines that look like:
>
>   [dir|file]name | [D|F] | mtime
>
> and I need to be able to have vimdiff only working on the
> [dir|file]name and ignore the rest of the line - is this possible
> somehow?
Check into the NarrowRegion plugin by Christian Brabandt
(https://www.vim.org/scripts/script.php?script_id=3075). I haven't used
it to do what you're asking for, but it seems to me that this plugin
might help you. Its worth a try, anyway.

Chip Campbell

Christian Brabandt

unread,
Apr 1, 2021, 1:01:43 PM4/1/21
to Vim Users

On Do, 01 Apr 2021, 'Philip Rhoades' via vim_use wrote:

> People,
>
> I live in vim and therefore use vimdiff most of the time for my needs but I
> have a use case where I only want to diff on the FIRST field of two files ie
> the files have lines that look like:
>
> [dir|file]name | [D|F] | mtime
>
> and I need to be able to have vimdiff only working on the [dir|file]name and
> ignore the rest of the line - is this possible somehow?
>
> Thanks,

Have a look at my plugin:
https://github.com/chrisbra/vim-diff-enhanced

The README.md has an example of that.

Best,
Christian
--
So kam ich unter die Deutschen. Ich forderte nicht viel und war
gefaßt noch weniger zu finden.
-- Johann Christian Friedrich Hölderlin

Philip Rhoades

unread,
Apr 1, 2021, 4:23:12 PM4/1/21
to Vim Users, Christian Brabandt, camp...@drchip.org, Br...@moolenaar.net
Christian, Charles, Bram,

Thanks so much for your responses! - they are much appreciated!

Phil.
> --

Philip Rhoades

unread,
Apr 2, 2021, 7:55:16 AM4/2/21
to vim...@googlegroups.com, Christian Brabandt
Christian,

I have installed your plugin, set diffopt in .vimrc and all the tests
work and

:EnhancedDiff histogram

command from your web page works but I can't get

EnhancedDiffIgnorePat ^[^;]\+;

or

EnhancedDiffIgnorePat ;[^;]\+$

to work with some manually created files like on your web page.

I tried looking at test.sh but I don't understand:

-c "if filereadable('vimrc') | so vimrc | endif'"

- what is "so"? - and there appears to be an unpaired single quote?

Any help appreciated!

Thanks,

Phil.

rwmit...@gmail.com

unread,
Apr 2, 2021, 9:07:10 AM4/2/21
to vim_use
'so' would be short for 'source'

Philip Rhoades

unread,
Apr 2, 2021, 10:43:46 AM4/2/21
to vim...@googlegroups.com, rwmit...@gmail.com
rwm,


On 2021-04-03 00:07, rwmit...@gmail.com wrote:
> 'so' would be short for 'source'


Ah . . of course . . thanks!

Phil.
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google
> Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vim_use/78f064a0-7f2e-4738-80fb-e55295375889n%40googlegroups.com
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/vim_use/78f064a0-7f2e-4738-80fb-e55295375889n%40googlegroups.com?utm_medium=email&utm_source=footer
Reply all
Reply to author
Forward
0 new messages