Vimdiff:如何将特定函数中的所有更改从一个文件放到另一个文件中?

时间:2022-09-12 19:31:09

In Vimdiff, I know I can use "do" or "dp" to move changes from one file to the other...but these are for individual changes. If I have to undo all changes inside a specific scope/selection (say undo all changes to a particular function, but leave the rest untouched), is there a way to do it in one go ?

在Vimdiff中,我知道我可以使用“do”或“dp”将更改从一个文件移动到另一个文件......但这些都是针对个别更改的。如果我必须撤消特定范围/选择内的所有更改(例如撤消对特定功能的所有更改,但保持其余部分不变),有没有办法一次性完成?

1 个解决方案

#1


14  

You can use a visual selection and the ex command :diffget/:diffput

您可以使用视觉选择和ex命令:diffget /:diffput

So, for example to get the changes for just the current insides of a code block ( { ... } )

因此,例如,仅针对代码块的当前内部({...})获取更改

Vi}:diffget<Enter>

To put the changes for the two enclosing levels including the lines with the brackets:

要对两个封闭级别进行更改,包括带括号的行:

V2a}:diffput<Enter>

Note that since these are ex commands the motions are linewise. Of course, you could use any range, so you can repeat the visual range, or use markers

请注意,由于这些是ex命令,因此运动是按行的。当然,您可以使用任何范围,因此您可以重复视觉范围,或使用标记

:'a,'bdiffput

etc. Use your imagination, this is vim :)

用你的想象力,这是vim :)

#1


14  

You can use a visual selection and the ex command :diffget/:diffput

您可以使用视觉选择和ex命令:diffget /:diffput

So, for example to get the changes for just the current insides of a code block ( { ... } )

因此,例如,仅针对代码块的当前内部({...})获取更改

Vi}:diffget<Enter>

To put the changes for the two enclosing levels including the lines with the brackets:

要对两个封闭级别进行更改,包括带括号的行:

V2a}:diffput<Enter>

Note that since these are ex commands the motions are linewise. Of course, you could use any range, so you can repeat the visual range, or use markers

请注意,由于这些是ex命令,因此运动是按行的。当然,您可以使用任何范围,因此您可以重复视觉范围,或使用标记

:'a,'bdiffput

etc. Use your imagination, this is vim :)

用你的想象力,这是vim :)