[The Computer Kid] How to Make Macros in Vim

0 views
Skip to first unread message

Conrad Sykes

unread,
May 15, 2013, 11:42:28 AM5/15/13
to the-comp...@googlegroups.com
Macros are one of Vims most powerful features. They allow you to record a complex task and then repeat that task in the future with a single key stroke. To make a macro in vim simply....


  • press "q" and then any key of your choice where you'd like to save your macro. For example if I type "q1" this will start recording my macro and save it to the "1" key for when I want to replay it.
  • Now at the bottom left hand side of your terminal you should see vim say's "recording". Now every action you perform is being recorded and saved. To end the recording simply press "q" again.
  • To replay your macro simply type "@" and the key where you saved your macro. So for our example above I would type "@1".
Note: it's important that when you run you're macro that you have your cursor in the right part of the screen. For instance if when you started your macro your cursor was at the beginning of a line then when you run your macro your cursor should be at the beginning of the line as well. To help with this you can use "^" to move your cursor to the beginning of a line or "$" to move to the end of a line. 

If you'd like to run a macro several times in a row you can type #@your-key (# = number of times to repeat, your-key = where you saved your macro).

--
Posted By Conrad Sykes to The Computer Kid at 5/15/2013 08:42:00 AM
Reply all
Reply to author
Forward
0 new messages