你不能在原始文件中这样做,但你可以这样做,而不使用单独的文件,只有单独的缓冲区。如果您在寄存器a中复制了一个子程序(例如,在可视模式下以“ay类型”)和寄存器b中的其他子程序,
原文链接:https://www.f2er.com/bash/390017.htmlenew | call setline(1,split(@a,"\n")) | diffthis | vnew | call setline(1,split(@b,"\n")) | diffthis
自动化:
let g:diffed_buffers=[] function DiffText(a,b,diffed_buffers) enew setlocal buftype=nowrite call add(a:diffed_buffers,bufnr('%')) call setline(1,split(a:a,"\n")) diffthis vnew setlocal buftype=nowrite call add(a:diffed_buffers,split(a:b,"\n")) diffthis endfunction function WipeOutDiffs(diffed_buffers) for buffer in a:diffed_buffers execute 'bwipeout! '.buffer endfor endfunction nnoremap <special> <F7> :call DiffText(@a,@b,g:diffed_buffers)<CR> nnoremap <special> <F8> :call WipeOutDiffs(g:diffed_buffers) | let g:diffed_buffers=[]<CR>
注意,如果Vim拒绝放弃更改的文件,可能需要设置隐藏选项(参见:h放弃)。