Search code examples
escapingvimstring-literalsquote

Is there a way to evaluate a literal string to quoted string in VIm?


That is, I want to build a quoted string on the fly that contains escape sequences (more preciously, escape characters)

Here is my code:

let s:char = "x"
let s:combo = "\\<C-" . s:char . ">"

Now s:combo contains "\\<C-x>", how can I eval it to "\<C-x>" to perform a combo with :normal?


Solution

  • See :h eval(). Something like:

    let s:char = "x"
    let s:combo = eval('"\<C-' . s:char . '>"')
    

    Note the double quotes inside the single quotes.