Let's say I have a file that contains a specific number that is always the same, something like the following:
1 1000
10 1000
100 1000
1000 1000
10000 1000
100000 1000
1000000 1000
10000000 1000
100000000 1000
I want to make this list like the following:
1 1000
10 1001
100 1002
1000 1003
10000 1004
100000 1005
1000000 1006
10000000 1007
100000000 1008
I'm struggling with a way of doing that. Only using a macro with Ctrl-A
wouldn't be enough for generating this final result because I'd always have to press Ctrl-A
once more when I go to the next line. Because of that, I thought I could use a command to act on every single line at once. I know the command :g/./norm $^A
would generate the following list:
1 1001
10 1001
100 1001
1000 1001
10000 1001
100000 1001
1000000 1001
10000000 1001
100000000 1001
I also know that the command :echo line('$')
gives me the number of the line that I'm currently editing. Is there any way of mixing these two commands? Something like :g/./norm $"echo line('$')"^A
just so I can use the number of the line as a multiplier factor for the number of times that I need to press Ctrl-A
?
That's the approach that I thought of when I tried to solve this problem... I'm not sure if this is the best suitable solution.
Edit:
I've also received suggestions on the comments for using g^A
after selecting all lines... The problem with g^A
is that it'll always edit the first appearance of the number on the line like the following:
1 1000
11 1000
102 1000
1003 1000
10004 1000
100005 1000
1000006 1000
10000007 1000
100000008 1000
The idea of selecting only the second column would be possible assuming that the columns are aligned. But for the files that I want to use this solution, I can't assume that they'll be aligned. Selecting everything and using 2g^A
only increases the amount that is increased in each line like the following:
1 1000
12 1000
104 1000
1006 1000
10008 1000
100010 1000
1000012 1000
10000014 1000
100000016 1000
Is there any workaround for this? Perhaps having a way of selecting everything after the first space? In a way that I don't rely on using ^VG
for selecting them because they're not aligned?
:help v_g_CTRL-A