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
nrformatscontrols which number formats Vim recognizes for numeric operations.octalin this option means numbers like010are interpreted as base-8.:set nrformats-=octalremoves 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
hexenabled if you still want<C-a>to work naturally on values like0xff. - This is especially useful when editing YAML, JSON-like data, and infra files where zero-padded decimals are common.