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

How do I prevent Vim from treating leading-zero numbers as octal when incrementing with Ctrl-A?

Answer

set nrformats-=octal

Explanation

By default, Vim treats numbers prefixed with a leading zero (like 007) as octal when you use <C-a> or <C-x> to increment or decrement them. This means pressing <C-a> on 007 yields 010 (octal 8) rather than the intuitive 008. Setting set nrformats-=octal removes octal from the list of recognized formats, ensuring all decimal-looking numbers increment in base 10.

How it works

  • nrformats is a comma-separated list of formats that <C-a> and <C-x> recognize
  • Default Vim value: bin,octal,hex
  • Default Neovim value: bin,hex (octal is already excluded)
  • nrformats-=octal removes octal from the list without affecting binary (0b1010) or hex (0xff) support
  • The -= operator removes an item from a comma-separated option

Example

With the default setting in Vim, placing the cursor on 007 and pressing <C-a> gives:

010

After adding set nrformats-=octal to your .vimrc, the same operation gives:

008

Tips

  • Add to your .vimrc to make it permanent: set nrformats-=octal
  • Verify the current value with :set nrformats?
  • Combine with set nrformats+=alpha to also increment alphabetical characters with <C-a>
  • This only affects Vim; Neovim users get sane decimal behavior out of the box

Next

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