Search code examples
vimconcatenationvi

In Vi/Vim how to map current item variable (v:val) with a string?


I'm trying to concatenate a string with range values in Vim using map function to no avail.

For example:

:for i in range(5) | put="No ".i | endfor

will output

No 0
No 1
No 2
No 3
No 4

but

:put=map(range(5), '"No" . v:val')

doesn't work. Is it possible to achieve the same result using a combination of put+map+range ?


Solution

  • You have to escape the quotes

    :put=map(range(5), '\"No\" . v:val')
    

    This is because put is not under :h :quote.