Storing Macro in VIM

Storing Macro in VIM

* Start recording macro using q command followed by name of macro. For an
example, if macro name is a then, qa.
* Perform task to be run in macro.
* Stop recording macro using q command.
* At this point macro content is stored in register (in register q in this case).
* Paste register content using “<macro_name>p command (“ap in this case). Note
that ” is part of command.
* Now you have content of macro. You can put it in .vimrc file.
Add below line to store macro with name a.
let @a = ‘<macro content>’

For a example, for simple copy paste macro (content is yyp)
let @a = ‘yyp’

Here ‘ character defines start and end of macro content. So if ‘ character is
part of macro, you need to use ‘ character twice i.e. ”.

For an example, if macro content is yy’p then,
let @a = ‘yy”p’

Enjoy Vimming 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s