在vimdiff窗口之间复制行时撤消diff put
如果在命令提示下,我运行在vimdiff窗口之间复制行时撤消diff put,vim,text,diff,text-editor,vimdiff,Vim,Text,Diff,Text Editor,Vimdiff,如果在命令提示下,我运行 vimdiff file1 file2 我得到一个vim实例,它有两个并排打开的文件。假设文件中的文本如下所示(文件1在左侧,文件2在右侧): 现在假设我的光标位于“foo”的“f”上,并且我希望将file1的第一行复制到file2的第一行 一种方法是使用v$y选择并拖动(复制)行,然后使用Ctrl+w l将光标移动到文件2的第一行,然后键入p粘贴复制的行。如果我这样做,然后我决定我根本不想这么做,我可以按u撤消我在file2中执行的粘贴命令 另一种方法是使用diff
vimdiff file1 file2
我得到一个vim实例,它有两个并排打开的文件。假设文件中的文本如下所示(文件1在左侧,文件2在右侧):
现在假设我的光标位于“foo”的“f”上,并且我希望将file1的第一行复制到file2的第一行
一种方法是使用v$y选择并拖动(复制)行,然后使用Ctrl+w l将光标移动到文件2的第一行,然后键入p粘贴复制的行。如果我这样做,然后我决定我根本不想这么做,我可以按u撤消我在file2中执行的粘贴命令
另一种方法是使用diff-put命令dp。但是,如果执行此操作后,我决定不打算执行此操作,我无法简单地按u撤消它,因为我的光标仍在文件1中,u命令将撤消对文件1的最新更改,而不是对文件2的最新更改。因此,我必须使用Ctrl+w l或Ctrl+w w将光标移动到文件2的窗口,然后按u
所以,我的问题是:在我像上面那样使用了dp之后,有没有什么简单的方法可以让我撤销它,而不必将光标移到另一个文件的窗口?确实没有用于此操作的命令,但您可以映射自己的命令。 将以下内容放入vimrc中,然后使用du执行差异撤消
nmap du:wincmd w:normal u:wincmd w
取决于您的工作流程,但我通常使用do将差异获取到我的文件中,而不是将差异放入另一个文件中的dp。这样,您就可以像往常一样使用u和ctrl+r
由于diff导航命令在这两个文件中的工作方式相同,因此您应该准备好了
下一个差异:]c
prev diff:
[c
在比较文件时,我喜欢使用vimdiff
或vim-d
。使用vimdiff
复制更改的一种方法是:
]c - advance to the next block with differences
[c - reverse search for the previous block with differences
do (diff obtain) - bring changes from the other file to the current file
dp (diff put) - send changes from the current file to the other file
其工作原理如下:
:diffget the same with do
:diffput the same with dp
如果有两个以上的窗口,这可能会表现得很奇怪(只是一个注释,不过这是一个完美的问题答案)。
]c - advance to the next block with differences
[c - reverse search for the previous block with differences
do (diff obtain) - bring changes from the other file to the current file
dp (diff put) - send changes from the current file to the other file
:diffget the same with do
:diffput the same with dp