Vim Tips Wiki
Advertisement

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 30 Printable Monobook Previous Next

created March 7, 2001 · complexity basic · author neuron · version 5.7


You can increment or decrement a number by pressing Ctrl-A or Ctrl-X when in Normal mode. The number can be at the cursor, or after the cursor.

The number can be decimal, hexadecimal or octal. You can also increment or decrement a single letter ("a...", "b...", "c..."). This is controlled with the 'nrformats' option.

Ctrl-A is very useful in a macro. As an example, suppose you type the line:

101 This is an item.

In Normal mode, enter the following to record a macro into the a register. This macro yanks the current line, then pastes it below, then increments the number.

qa
Y
p
Ctrl-A
q

Now type 15@a to perform the macro 15 times. You will see:

101 This is an item.
102 This is an item.
103 This is an item.
104 This is an item.
and so on

On Windows, your _vimrc file may source mswin.vim. That script sets Ctrl-A to Select All. If you want to use Ctrl-A in Normal mode to increment a number, you need:

:nunmap <C-A>

References

Comments


Advertisement