开发者

Mark difference as ok in vimdiff

开发者 https://www.devze.com 2023-04-11 17:24 出处:网络
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 elim开发者_如何

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 elim开发者_如何学JAVAinating 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).


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


I don't think there is a built-in way to do that. But the way that occurs to me is to do substitute on the files, then rediff.

E.g., if that name change is OK, then just substitute in both files:

%s/Name: Donald Duck/Name: placeholder_1/g    ; in file 1
%s/Name: Daisy Duck/Name: placeholder_1/g     ; in file 2

You could do this with e.g. sed or perl before starting vim -d as well.

Now those will match. But a change from Donald Duck to Mickey Mouse won't, nor a change from Daffy Duck to Daisy Duck.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号