Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vimdiff: How to put all changes inside a particular function from one file to another?

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 ?

like image 519
TCSGrad Avatar asked May 23 '11 06:05

TCSGrad


People also ask

How do I expand in Vimdiff?

Ctrl + W , w - Switch to the other split window ( Ctrl + W , Ctrl + W does the same thing, in case you let go of the Ctrl key a bit later)


1 Answers

You can use a visual selection and the ex command :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

:'a,'bdiffput

etc. Use your imagination, this is vim :)

like image 68
sehe Avatar answered Oct 26 '22 17:10

sehe