tools/vim
Incrementing selected numbers in vim
seul chan
2021. 3. 31. 03:14
Vim command for incrementing numbers sequentially.
my_array[1] = 0;
my_array[2] = 0;
my_array[3] = 0;
my_array[4] = 0;
my_array[5] = 0;
my_array[6] = 0;
my_array[7] = 0;
If you want to increment numbers inside my_array
1. with cursor on the first 0
in the first line
2. blockwise select with Ctrl-V
- enter blockwise-visual mode
- and select all wanted number
Vim keys are will be...
<Ctrl-V>
6j # or simply jjjjjj
v
for visual mode,V
for line-visual mode,Ctrl-V
for blockwise visual mode. For more information, read:help ctrl-v
Then you'll got selected numbers
3. increment with g Ctrl-A
<Ctrl-A>
is add count to the number or alphabetic character.g <Ctrl-A
each one will be incremented if several lines are selected
You can see help text in
:help ctrl-a
Vim key strokes will be
g
<Ctrl-a>
Then, boom!
All in one
So, all keystrokes will be (NO enter, newline is just for readability
It suppose to start from first line, first character (m
)
f0 # find 0
<Ctrl-V>
6j
g
<Ctrl-a>
Here's whole gif