Is there a way in Vim to do the following:

let S = '[''123'', ''456'', ''789'']'
let L = parseStringToList(S)
" L is a list containing the string '123', '456', and '789'
  • Not sure I understand. After the let S... line, you have a list that contains only Strings. So what are you trying to do? – Christian Brabandt Dec 14 '18 at 16:15
  • @ChristianBrabandt, after the let S, it's a string containing a textual representation of a list, not a list. – Jim Stewart Dec 14 '18 at 16:17
  • ah, I missed that. – Christian Brabandt Dec 14 '18 at 16:43

You can do this with eval:

let S = '[''123'', ''456'', ''789'']'
let L = eval(S)

Generally, using eval is something you should be wary of. Don't run it on untrusted data. But this does solve your problem.

It's possible there's a completely different approach you should be using, but without context, it's hard to say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.