10 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

You could do this by recording a macro, then using the global ex command to execute the macro n number of times for each line in the file. After recording the macro, undo the changes done while ...
user avatar
  • 3,109
8 votes
Accepted

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Here's a substitution that solves the problem: :%s/\(.*\)1\(.*\)/\=join(map(range(1, 12), 'submatch(1) . v:val . submatch(2)'), "\n") The substitution matches each line that contains "1" and ...
user avatar
  • 861
6 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Two ways: Use a macro! Starting with 1stlineblahblahblah/nt/1blah 2ndlineblahblahblah/nt/1blah 3rdlineblahblahblah/nt/1blah With your cursor on the first line qqyyp$?\d<CR><Ctrl-a>q ...
user avatar
  • 1,470
5 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

I find it easiest to use macros for one-shot tasks like that. Just start recording a macro with q + name of register and do the task once. I see one repeatable task here: Select the line yank paste (...
user avatar
  • 249
3 votes

How to append a random number between a range [1,10] at the end of each line in vim

As long as you don't mind the quality of the random process generation: :%s/\s*$/\=' ' . (1 + str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) % 10)/ It basically replaces the end of ...
user avatar
  • 9,250
3 votes
Accepted

How to copy each line 19 times, incrementing two different numbers by 180?

You can record a macro, carry out your instructions, close the macro, then run it. In your case you may start with the cursor at the beginning of the line to copy. Press qa to start recording macro '...
user avatar
2 votes

How to copy each line 11 times, incrementing the last "1" in each line from 2-12

Save the following macro and use it for each line: qqyy11p/\/\zs1<CR><C-v>10jg<C-a>q The main difference over the other answers is that this makes use of g<C-a> on a column ...
user avatar
  • 1,522

Only top scored, non community-wiki answers of a minimum length are eligible