diffput到多个缓冲区?

Cor*_*ein 6 vim diff vimdiff

有时在编辑三个文件时vimdiff我想将一个文件从一个文件复制到另外两个文件.通常这将完成如下:

:diffput 2
:diffput 3
Run Code Online (Sandbox Code Playgroud)

但是,:help diffput这说:

                        *:diffpu* *:diffput* *E793*
:[range]diffpu[t] [bufspec]
Run Code Online (Sandbox Code Playgroud)

这让我很好奇是否bufspec允许您指定多个缓冲区.我尝试使用文档,然后猜测,但没有运气.

:help bufspec
:diffput 2,3
:diffput 2 3
Run Code Online (Sandbox Code Playgroud)

是否可以在diffput命令中指定多个缓冲区?

She*_*tJS 3

接受的答案要求您指定哪些缓冲区将接收差异。从你的问题措辞来看,听起来你想将更改推送到每个其他缓冲区(例如,如果你有 10 个 diff 缓冲区——重新编译 vim 后——你需要 diffput 到缓冲区 1,2,3,4,5 ,6,7,8,9)

我使用以下命令推送到所有缓冲区:

function! GetDiffBuffers()
    return map(filter(range(1, winnr('$')), 'getwinvar(v:val, "&diff")'), 'winbufnr(v:val)')
endfunction

function! DiffPutAll()
    for bufspec in GetDiffBuffers()
        execute 'diffput' bufspec
    endfor
endfunction

command! -range=-1 -nargs=* DPA call DiffPutAll()
Run Code Online (Sandbox Code Playgroud)

然后运行:DPA以推送到所有缓冲区。