Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ctrl-A in Vim command line to increment a number

Tags:

vim

In normal mode (in Vim) if the cursor is on a number, hitting Ctrl-A increments the number by 1. Now I want to do the same thing, but from the command line. Specifically, I want to go to certain lines whose first character is a number, and increment it, i.e., I want to run the following command:

:g/searchString/ Ctrl-A

I tried to store Ctrl-A in a macro (say a), and using :g/searchString/ @a, but I get an error:

E492: Not an editor command ^A

Any suggestions?

like image 605
user10 Avatar asked Jan 14 '10 04:01

user10


People also ask

What does Ctrl w do in Vim?

Ctrl-w = tells Vim to assign an equal number of lines to each viewport.

How do you jump between lines in Vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.


1 Answers

You have to use normal to execute normal mode commands in command mode:

:g/searchString/ normal ^A

Note that you have to press Ctrl-VCtrl-A to get the ^A character.

like image 194
Christian C. Salvadó Avatar answered Oct 07 '22 19:10

Christian C. Salvadó