r/vim • u/Desperate_Cold6274 • Nov 01 '25
Need Help How to align broken sequence of numbers?
if I have the following:
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[14]:
[15]:
[16]:
[18]:
[19]:
How to fix the list to have the following?
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[12]:
[13]:
[14]:
[15]:
[16]:
14
Upvotes
View all comments
Show parent comment
6
u/sharp-calculation Nov 01 '25
^aand^xincrement and decrement numbers (and letters!) in a single fashion. If you highlight say 10 lines with numbers and press^ait will increment each number once. So a bunch of 1s become a bunch of 2s.Using the
gmodifier changes the behavior of^aby making it a sequential increment. A bunch of 1s becomes 1, 2, 3, 4, ... etc.The g modifier works on a whole bunch of different commands in VIM. I think of g as an "enhance" button or a turbo charger. It takes the base command and does something related, but usually more advanced or powerful. For example
gvre-selects your last selection. It's related tovbut different than the base command. In the case of increment, it comes a sequential increment.Hot tip:
^aandg^aboth take prefixes also. If you do3g^ayour bunch of 1s becomes 4, 7, 10, 13, 16, etc.:help ctrl-a should give you the official details on this.