10

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 ?

TCSGrad
  • 11,898
  • 14
  • 49
  • 70

1 Answers1

15

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 :)

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Great answer - not only did u nail the question, you showed me a different way to visually select a block !! – TCSGrad May 23 '11 at 07:24
  • +1 for teaching me that I can do `diffput` and `diffget` on ranges. Also, it would've never occur to me to use `diffput` and `diffget` for selective _undo_, guess my imagination kinda sucks... :) –  Oct 01 '13 at 07:19