I have 2 large files to take vimdiff. In vimdiff output I want to ignore lines showing diff but have a particular word.
e.g. in my case I want to ignore diff of all lines with prefix WARNING:
in my files.
Thanks,
In order to achieve this, you could add the following to your .vimrc (a simple-minded modification from the example found by running :h diffexpr
within vim):
set diffexpr=MyDiff()
function! MyDiff()
let opt = ""
if exists("g:diffignore") && g:diffignore != ""
let opt = "-I " . g:diffignore . " "
endif
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-b "
endif
silent execute "!diff -a --binary " . opt . v:fname_in . " " .
\ v:fname_new . " > " . v:fname_out
endfunction
It's noteworthy that the functionality provided by the -I
(or --ignore-matching-lines=
) switch for diff
will ONLY ignore any changed lines where the line in BOTH (or all) files matches this expression.
See man diff
for more details on the --ignore-matching-lines=RE
switch and :h diffexpr
within vim for more details on this.
EDIT: Added the optional variable g:diffignore
to control what pattern to use. Also used function!
to force replacement on definition.
I've looked for a solution to this for a long time and I found the EnhancedDiff plugin to be the easiest solution which makes your diffs slightly more intelligent to begin with :)
Use the plugin manager of your choice:
git clone https://github.com/chrisbra/vim-diff-enhanced.git ~/.vim/bundle/vim-enhanced-diff
:Helptags
(only needed once after the installation to install the documentation)NeoBundle 'chrisbra/vim-diff-enhanced'
Plugin 'chrisbra/vim-diff-enhanced'
Plug 'chrisbra/vim-diff-enhanced'
Using vimdiff
, nvim -d
or diffthis
for example
:EnhancedDiffIgnorePat ^WARNING:.*
:diffupdate
Why don't you filter the files before invoking vimdiff?
If you're using Bash or zsh, you can do it with a single command: