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

How do I make Ctrl-A and Ctrl-X increment and decrement alphabetical characters in Vim?

Answer

set nrformats+=alpha

Explanation

By default, Vim's <C-a> and <C-x> commands only increment and decrement numbers (decimal, hex, binary). Adding alpha to nrformats extends this behavior to single alphabetical characters, so pressing <C-a> on a gives b, on z gives a (wrapping), and on Z gives A.

How it works

  • nrformats controls which value formats <C-a> and <C-x> recognize and modify
  • set nrformats+=alpha appends alpha to the existing list
  • Vim increments single lowercase or uppercase letters in sequence (a→b, Z→A)
  • Wraps around: za, ZA
  • Only applies to single characters — it won't increment multi-character words
  • Count prefix works: 5<C-a> on a gives f

Example

With set nrformats+=alpha, place the cursor on the character in:

step a

Press <C-a> to get:

step b

Press 5<C-a> to advance 5 letters:

step g

Tips

  • Record a macro and use <C-a> to produce auto-incrementing list labels: a), b), c), ...
  • Combine with a visual block g<C-a> on a column of identical letters to create a sequence: a, b, c, ...
  • To check current value: :set nrformats?
  • Reference: :help nrformats

Next

How do I check if a specific Vim feature or capability is available before using it in my vimrc?