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

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 007010 (octal!)
hex prefix 0x 0xff0x100
bin prefix 0b 0b11110b10000
alpha single letter ab
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-=octal to your vimrc to remove only octal without affecting hex/bin
  • set nrformats+=alpha lets you increment single letters — great for creating labeled lists with macros: <C-a> on a gives b, c, d...
  • In visual mode, g<C-a> increments each selected number sequentially (1, 2, 3...) instead of by the same amount

Next

How do I insert the current date or time into the buffer using Vim's built-in expression evaluation?