I am trying Vim
capabilities and stuck with this task - addition the incrementing number to the end of each line.
Testing lines:
text
text
text
text
text
This command works partially:
:let n=1 | g/text/s/$/\=n/ | let n+=1
Result:
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 - text =n
:
: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):
s/$/string\=n/
s/$/'string'\=n/
or this:
s/$/\='string'n/
- Can I use multiple variables in the substitute expression by separating them from each other like in the
bash
?
Example:
s/$/\={var_1}{var_2}{var_3}/
3. Do you know more suitable/simple way for solving this task?
text
? And do thetext
lines start on line 0? – James Jan 17 '19 at 19:31