Question

I want to insert a sequence of numbers but I need to repeat every number in n lines, I mean:

Original file       New file
1                   1,1
2                   1,2
3                   1,3
4                   2,4
5                   2,5
6                   2,6
7                   3,7
8                   3,8
9                   3,9
Was it helpful?

Solution

You can use a :help sub-replace-expr. A simple .* will match the number, and you can then concatenate the result, using submatch(0) to work with the match:

:%s#.*#\=(submatch(0)+2)/3 . ',' . submatch(0)#
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top