How do I configure what types of numbers Vim recognizes when using Ctrl-A and Ctrl-X to increment or decrement?
Answer
:set nrformats=
Explanation
The nrformats option controls which number formats <C-a> (increment) and <C-x> (decrement) recognize. The default includes octal, which means any number with a leading zero is treated as octal — a frequent surprise when incrementing version numbers or zero-padded values like 007.
How it works
Default value: bin,octal,hex
| Format | Trigger | Example |
|---|---|---|
octal |
leading 0 |
007 → 010 (octal!) |
hex |
prefix 0x |
0xff → 0x100 |
bin |
prefix 0b |
0b1111 → 0b10000 |
alpha |
single letter | a → b |
unsigned |
any number | prevents wrapping below 0 |
Setting nrformats= (empty) makes <C-a> and <C-x> treat all numbers as decimal.
Example
With default nrformats=bin,octal,hex:
007 → (Ctrl-A) → 010 ← octal!
With set nrformats= (empty):
007 → (Ctrl-A) → 008 ← decimal
Tips
- Add
set nrformats-=octalto your vimrc to remove only octal without affecting hex/bin set nrformats+=alphalets you increment single letters — great for creating labeled lists with macros:<C-a>onagivesb,c,d...- In visual mode,
g<C-a>increments each selected number sequentially (1, 2, 3...) instead of by the same amount