Domanda

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
È stato utile?

Soluzione

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)#
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top