Automatically generating text with Vim, using patterns like incrementing numbers, etc.

Vim supports automatically generating text following a pattern, via macros, motions and functions. For example, the following generates a sequence of numbers from 1 to 10:


Breaking down:

  • i1<esc> write 1 and back to normal mode
  • qq start recording a macro in the register q
  • Yp yank the line and paste it below
  • <c-a> increment it
  • q stop recording the macro
  • 8@q repeat the macro in the register q 8 times.

Other facilities for automation include using functions in the replacement of a :substitute command, looping over text, etc.