In Neovim, I’m a big fan of CTRL-a to increment a number (and CTRL-x to decrement a number), however when I have dash before the number (e.g. “sprint-23”), this is interpreted as a negative number so incrementing the value
goes to 22 (because -22 is one greater than -23). We can fix this.
The short answer is to add this to your Neovim configuration
vim.opt.nrformats:append('blank')
or if you’re using Vim
set nrformats+=blank
Neovim has a number of algorithms for identifying numbers to increment/decrement and they are controlled by nrformats (see :help nrformats).
By adding blank to the nrformats, Neovim will
treat numbers as signed or unsigned based on
preceding whitespace. If a number with a leading dash has its
dash immediately preceded by a non-whitespace character (i.e.,
not a tab or a " "), the negative sign won't be considered as
part of the number. For example:
Using CTRL-A on "14" in "Carbon-14" results in "Carbon-15"
(without "blank" it would become "Carbon-13").
Using CTRL-X on "8" in "Carbon -8" results in "Carbon -9"
(because -8 is preceded by whitespace. If "unsigned" was
set, it would result in "Carbon -7").
How to Add blank to nrformats
We can add blank to nformats by running this command
:set nrformats+=blank
or we can update our Neovim configuration in our init.lua file with
vim.opt.nrformats:append('blank')
Vim Compatibility
Vim also supports blank as an nrformats value and it looks like this was originally an issue and improvement made in Vim that was ported over to Neovim.
See https://github.com/vim/vim/issues/15033
Leave a Reply