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

How do I make Ctrl-A and Ctrl-X increment and decrement alphabetic characters?

Answer

:set nrformats+=alpha

Explanation

By default, <C-a> and <C-x> only increment and decrement numbers (decimal, hex, and octal depending on format). Adding alpha to nrformats extends this behaviour to single alphabetic characters, making it easy to cycle through a→b→c or A→B→C without retyping.

How it works

  • nrformats controls which formats <C-a> and <C-x> recognise
  • Supported values: bin (binary 0b), hex (hex 0x), octal (leading 0), alpha (single letters)
  • +=alpha appends to the existing value without discarding bin and hex
  • With alpha set, <C-a> on a letter advances it one position; wraps from z back to a

Example

With the cursor on a in this list:

step a: install dependencies
step a: run tests
step a: deploy

Presing <C-a> increments a to b. Use . to repeat on the next occurrence.

Tips

  • Use a visual-block selection across a column of letters and press <C-a> to increment all at once
  • Combine with g<C-a> on a visual selection to create ascending sequences: a, b, c…
  • To see the current value: :set nrformats?
  • Put :set nrformats+=alpha in your vimrc to make it permanent

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?