문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top