Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore lines with particular words in vimdiff output

Tags:

vim

vimdiff

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,

like image 417
ravi Avatar asked Jan 14 '12 11:01

ravi


2 Answers

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 :)

1. Installation (https://github.com/chrisbra/vim-diff-enhanced#installation)

Use the plugin manager of your choice:

  • Pathogen
    • 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
    • NeoBundle 'chrisbra/vim-diff-enhanced'
  • Vundle
    • Plugin 'chrisbra/vim-diff-enhanced'
  • Vim-Plug
    • Plug 'chrisbra/vim-diff-enhanced'

2. Diff as usual

Using vimdiff, nvim -d or diffthis for example

3. Set the filter

:EnhancedDiffIgnorePat ^WARNING:.*

4. Re-diff

:diffupdate
like image 168
Wolph Avatar answered Oct 01 '22 18:10

Wolph


Why don't you filter the files before invoking vimdiff?

grep -v "^WARNING" file1 > file1_w; 
grep -v "^WARNING" file2 > file2_w; 
vimdiff file1_w file2_w

If you're using Bash or zsh, you can do it with a single command:

vimdiff <(grep -v "^WARNING" file1) <(grep -v "^WARNING" file2)
like image 29
pdjota Avatar answered Oct 01 '22 18:10

pdjota