Search code examples
vimvimdiff

Mark difference as ok in 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).


Solution

  • 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