Saving vim macros

Use q followed by a letter (for example ‘x’) to record a macro, then press q to end the macro definition. The pattern surrounded by the starting and ending 'q' during this definition just goes into one of the copy/paste registers (in this case, register ‘x’) so you can paste it with the"xp or "xP commands in normal mode, where x is the register to paste. Typing "xp in normal mode inserts the contents in register x and exits back to normal mode.

To save it, you open up .vimrc and paste the contents while defining the macro using let @x, then the register will be around the next time you start vim.
The format is something like:

let @q = 'macro contents'

Be careful of quotes, though. They would have to be escaped properly.

So to save a macro 'x', you can do:

  • From normal mode: qx
  • enter whatever commands
  • From normal mode: q
  • open .vimrc
  • insert a line let @x = '...' (see the following)
  • For the above ... pattern, you can use "xp just at the place where the pattern should be placed. But this is not essential, you can just type in the macro definition.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)