Question

I'm using vimdiff to merge a changes from another group's file into our file. Not all changes should be accepted, so I have to do it manually. However, I was wondering if there is a way to tell vimdiff to accept several changes at once. i.e. instead of accepting only the next change, I want to able to accept the next 10 changes at once. Right now I'm using "]c" to jump to the next change and "do" to accept that change. The file is 250000 lines and I'm only at line 5000 ...

Sincerely, Hagai

Was it helpful?

Solution

You can accomplish exactly what you want with macros, in a nutshell:

  1. In normal mode, press 'q' and a random letter, lets say 'f': This will start recording a macro in the register 'f'.
  2. Perform the actions you want to repeat: In this case ']c' and 'do'.
  3. Stop recording the macro: Just press 'q' again.

Now you can use it by typing '@f' in normal mode and it will replay the actions recorded in the macro 'f'. From there you have several options:

  • If you type '@@' vim will replay the last macro. Hint: if you just keep the combination pressed in the keyboard it will do it line by line very fast.
  • If you type '1000@f' vim will replay the last macro 1000 times, which is pretty much what you are looking for.
  • If you want to save some typing, you can record a new macro i.e. 'g' performing '1000@f', that way '@g' will call '1000@f', although if you use '@@' after '@g' it will do it line by line.

There is a nice tutorial here: http://www.thegeekstuff.com/2009/01/vi-and-vim-macro-tutorial-how-to-record-and-play/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top