I am trying
Vim capabilities and stuck with this task - addition the incrementing number to the end of each line.
text text text text text
This command works partially:
:let n=1 | g/text/s/$/\=n/ | let n+=1
text1 text2 text3 text4 text5
But I want to have space between the added numbers and the 'text'.
The adding of space ' ' before the
\=doesn't work, because the
\= should be in the beginning of substitute expression, else it is not parsed as an expression, but inserted literally -
:let n=1 | g/text/s/$/ \=n/ | let n+=1 ### doesn't work as expected
So, the questions:
- Is it possible to insert a string in the substitute expression?
Like this (the
n is the variable):
- Can I use multiple variables in the substitute expression by separating them from each other like in the
3. Do you know more suitable/simple way for solving this task?