vimtricks.wiki Concise Vim tricks, one at a time.

How do I create an incrementing number sequence from identical numbers in Vim?

Answer

g<C-a> in visual mode

Explanation

When you have multiple lines with the same number and want to turn them into a sequence (1, 2, 3...), select them in visual mode and press g<C-a>. Each number on each selected line gets incremented progressively — the first by 1, the second by 2, and so on.

How it works

  • Select multiple lines containing the same number using V (linewise visual)
  • Press g<C-a> to increment each number progressively
  • The first selected line's number increases by 1, the second by 2, the third by 3, etc.
  • g<C-x> does the same but decrements instead

Example

Start with these lines (all containing 0):

0. item
0. item
0. item
0. item
0. item

Select all lines with Vj4 then press g<C-a>:

1. item
2. item
3. item
4. item
5. item

Tips

  • Works with any starting number, not just 0 — starting from 10 gives 11, 12, 13...
  • Use a count: 3g<C-a> increments by 3 each step (3, 6, 9, 12...)
  • This is a Vim 8+ and Neovim feature — not available in older Vim versions
  • Much faster than recording a macro with <C-a> for numbered lists

Next

How do I return to normal mode from absolutely any mode in Vim?