Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark difference as ok in vimdiff

Tags:

vim

vimdiff

I have a couple of large json files that I need to check for errors and was wondering if it is possible to mark a difference as ok and have that apply for the whole diff session thereby eliminating it further down in the file.

example

Name: Donald Duck    |   Name: Daisy Duck

Here I would like to be able to mark this change as an "ok" diff (i.e. I expect the name and apparent sex change).

like image 203
Sedrik Avatar asked Oct 07 '11 15:10

Sedrik


People also ask

How do you get to the next difference in Vimdiff?

You can jump to the "next difference" ( ] c ), but this will jump to the next line with a difference.

How do I copy and paste in Vimdiff?

Use dp for copying the current difference block to another side, do for copying from another side to the current. dp means "put", do means "obtain". The current difference block is where your caret is.

How do I save Vimdiff output?

Open a terminal and run this command: vimdiff file1. txt file2. txt -c TOhtml -c 'w!


1 Answers

Well, the way to do it in vim, would simply to do a custom diff expression

e.g. this should go in your .vimrc

set diffexpr=MyDiff()
function! MyDiff()
    let opt = ""
    if &diffopt =~ "icase"
        let opt = opt . "-i "
    endif
    if &diffopt =~ "iwhite"
        let opt = opt . "-Ewb "
    endif
    silent execute "!diff -I 'Duck' " . opt . v:fname_in . " " . v:fname_new .
                \  " > " . v:fname_out
endfunction

Of course, you'd want to make it more flexible than that, but this should give you the general method

like image 73
sehe Avatar answered Sep 23 '22 03:09

sehe