1

Is it possible to convert a character from printable to literal? (like "<c-o>" to "\<c-o>", or "<F1>" to "\<F1>"), other than by using a dicionary with all special characters. What about the other way around?

My aim to pass a mapping extracted from :maps to feedkeys, but feedkeys does not accept non-literal special characters.

1

The following should work:

let l:literal = eval('"'.escape('<c-o> <f1> <bar> <ll> \e "', '\<"').'"')

When vim encounters "\<invalid>" it simply replaces it with <invalid>. A side effect of using double quotes is you need to also escape the characters \ and ", but this is simple to do.

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.