Skip to content


Creating macros in vim

Vim Macro Cheat Sheet

  • Start recording a macro with q (register name). If you want to record a macro called x, then you hit qx.

  • Start performing the actions for the macro. For this particular video, I yanked a line with yy, paste it with p, and either incremented or decremented the first number in the line with Ctrl-A and Ctrl X respectively.

  • After you are done recording the macro, use q to quit recording. Note, you can’t be insert mode for this to work

  • To recall a macro, use @ (register name). To call macro x, you hit @x. You can run the macro multiple times if you precede it with a number. 10@x

  • To see the contents of the macro use :register. To see whats in register x, all you need to do is :reg x.

  • Your macro should automatically persist across sessions if you haven’t modified your viminfo. To verify the contents of your viminfo, run :set viminfo?. If you see <50,s10 … this means that your registers can be 50 lines and 10KB.

Posted in Geek Vids.

Tagged with , .

  • llimllib
    You can also use macros in macros, which I just discovered this week.
  • I enjoy how much things are so additive in vim. I'm still learning.
blog comments powered by Disqus