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
nrformatscontrols which formats<C-a>and<C-x>recognise- Supported values:
bin(binary0b),hex(hex0x),octal(leading0),alpha(single letters) +=alphaappends to the existing value without discardingbinandhex- With
alphaset,<C-a>on a letter advances it one position; wraps fromzback toa
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+=alphain yourvimrcto make it permanent