How to increase or decrease a number in Vim
In Normal mode, Ctrl-a adds one to the number under or after the cursor and Ctrl-x takes one away. Put a count first for more, so 5Ctrl-a adds five. In Visual mode, gCtrl-a numbers the selected lines 1, 2, 3.

The office down the street has called back about Friday's catering order. Five more burritos, two fewer guacamoles. The cursor is at the start of the burritos line in catering.js, a few characters before the 12, and you'd rather not do the sum in your head and type it over the old number.
burritos: 12, burritos: 17,Change the catering order
Ctrl-a is Ctrl and A pressed together, and Ctrl-x is Ctrl and X. The cursor is at the start of the burritos line.
This editor needs a keyboard. Read on, and play it at your computer.
Which number Vim changes
Ctrl-a changes the number under the cursor. When the cursor isn't on one, Vim looks right along the line and takes the first number it finds, so you rarely need to move onto it first. It never looks past the end of the line, and on a line with no number after the cursor nothing happens.
That matters for version numbers. To Vim, 1.4.2 is three numbers with dots between them, and each counts on its own. With the cursor on the 4, Ctrl-a gives 1.5.2 and 10Ctrl-a would give 1.14.2. Nothing carries into the next part.
A bug-fix release
You want the version to say 1.4.3. The cursor is at the start of the line, in Normal mode, and you press Ctrl-a. What does the line say now?
Negative numbers
A minus sign right before the digits belongs to the number. Ctrl-x on a 1 gives 0 and then -1, and Ctrl-a on -3 climbs to -2. The walk-in freezer runs at -18, and the manager wants it two degrees colder.
freezer: -18, freezer: -20,-18 down to -20Leading zeros, hex and octal
Vim keeps a number's width. 0099 becomes 0100. Hex keeps its 0x and its zeros, so 0x00ff becomes 0x0100, and binary works the same way with 0b.
The nrformats option decides which kinds Vim knows. Neovim's default is bin,hex, and so is Vim's while it runs on its defaults.vim, which it does until you have a vimrc of your own. After that Vim's built-in default applies, and it adds octal. A number with a leading zero then counts in eights, so 007 becomes 010, and 0099, which can't be octal, comes out as 100. Put set nrformats-=octal in your vimrc if your files have zero-padded numbers like order tickets.
ticket: 0099ticket: 0100Number a list 1, 2, 3 in Visual mode
Select some lines first and Ctrl-a adds to the first number on every one of them. V selects the line the cursor is on, and each j stretches the selection down a line. When every price on the menu goes up a dollar, that's V j j and then Ctrl-a.
Carnitas $9.50Al pastor $10.50Veggie $8.00Carnitas $10.50Al pastor $11.50Veggie $9.00gCtrl-a adds a little more on each line: one on the first selected line, two on the second, three on the third. A list where every line starts with 1., which is what you get after pasting one line a few times, becomes 1, 2, 3, 4 once you select from the second line down. A count sets the step, so on a column of zeros 10gCtrl-a gives 10, 20, 30.
Number the rolling steps
The burrito-rolling steps for new staff were pasted from one line, so every step says 1.. The cursor is on the first step.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | Does |
|---|---|
| Ctrl-a / Ctrl-x | adds one to / takes one from the number under or after the cursor |
| 5Ctrl-a / 5Ctrl-x | adds five / takes five |
| . | repeats the last one, with the same count |
| Ctrl-a / Ctrl-x in Visual mode | changes the first number on every selected line by one |
| gCtrl-a / gCtrl-x in Visual mode | one on the first line, two on the second, and so on |
| 2gCtrl-a in Visual mode | the same in steps of two |
| Ctrl-v, select a column, Ctrl-a | only the numbers inside the column |
set nrformats-=octal | 007 becomes 008 instead of 010 |
set nrformats+=unsigned | a dash in a date is no longer a minus sign |
set nrformats+=alpha | a single letter counts too, so a becomes b |