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

How do I stop <C-a> from treating leading-zero numbers as octal?

Answer

:set nrformats-=octal<CR>

Explanation

By default, Vim may treat numbers with leading zeros as octal when you use <C-a> and <C-x> for increment/decrement. That behavior is historically correct but surprising in modern codebases, where values like 007 are often identifiers, padded decimals, or strings in config files. Removing octal from nrformats makes numeric editing far more predictable.

How it works

  • nrformats controls which number formats Vim recognizes for numeric operations.
  • octal in this option means numbers like 010 are interpreted as base-8.
  • :set nrformats-=octal removes octal recognition from the current option value.
  • After that, <C-a> and <C-x> treat leading-zero numbers as decimal, reducing accidental jumps.

Example

Suppose the cursor is on:

007

With default octal behavior, incrementing can yield:

010

After running:

:set nrformats-=octal

Incrementing behaves as decimal and yields:

008

Tips

  • Make it persistent in your config: set nrformats-=octal.
  • Keep hex enabled if you still want <C-a> to work naturally on values like 0xff.
  • This is especially useful when editing YAML, JSON-like data, and infra files where zero-padded decimals are common.

Next

How do I open another file without changing the alternate-file mark (#)?