Friday, November 27, 2020

help with map(), please!

I'm having a bit of a problem with map(). I've had problems with map() before, and consequently I really really hate to use it.
Here goes:

1: construct a comment:
"   Testing: one two | three four | five | six |
"            seven | eight |;
2. grab characters:
fo<ctrl-v>j$"ay

3. convert to list:
let list= split(@a,'\s*|\s*;\=',' ')
4. Now, try to use map():
call map(list,"substitute(v:val,'<&>','','ge')")

Intent: to put <...> around every argument. Now, this isn't really my final intent for this, but if I could get that substitute to work, it'd be a nice start. Please note, the request is on how to get a substitute() to work with map(), not to put angle brackets around every list element, for which :help map() already has an example.
5. Bonus request: my construction above carefully gets a newline into the list. Using :echo string(list):
['one two', 'three four', 'five', 'six', '
seven', 'eight', '                    ']
    I cannot seem to get rid of the newline, but its probably due to my lack of success with substitute().

I've spent about three hours on this so far, with multiple attempts, all unsuccessful. Perhaps an extra example in help map() illustrating how to do this would be of use?

Thank you,
Chip Campbell

No comments:

Post a Comment