in

CodePrairie .NET

South Dakota .NET User Group

chrisortman

How to execute a VIM macro over a line range

Macros in VIM are extremely useful for making lots of changes.

One thing that has always bothered me though is that I couldn't run the macro over a movement or line range and had to run it manually for each line.

The secret sauce is the :norm command.

Say you have recorded a macro in the q register.

To apply it to lines 3 - 6 use:

:3,6norm! @q

If you like VIM and want to learn more, I suggest you check out Aaron's screencasts.

Published Feb 06 2008, 05:17 AM by chrisortman
Filed under:

Comments

 

lejeczek said:

nice one! :) cheers

July 14, 2009 3:19 PM
 

Chris said:

Woot, this is extremely useful! Kuods for the links!

July 13, 2010 1:09 AM
 

Dean said:

Cheers, this is very handy to know.

October 6, 2010 1:09 AM
 

David said:

You know, I couldn't get :normal @q to work, but your method, with $ as the end range did the trick.  Thank you.

March 5, 2013 10:01 PM

Leave a Comment

(required)
(optional)
(required)
Add
Powered by Community Server (Commercial Edition), by Telligent Systems