I have mapping \\' (leader leader apostrophe) within my .vimrc.
The mapping works just fine.

I have recorded a macro to key e using this mapping.
qe ... steps ... q
The macro works just fine.

then I dumped the macro to text with "ep
The macro text is \\'0<80>kd

I have placed this handy macro in my .vimrc as
let @e ='\\'0<80>kd'

The problem is I can't work out how to escape the apsotrophe that appears just before the 0.

How can I do this?


You can use two single quotes to do this:

let @e = '\\''0<80>kd'

See :help literal-string:

This string is taken as it is. No backslashes are removed or have a special meaning. The only exception is that two quotes stand for one quote.

(Emphasis mine)

You could also have done this by using a regular double quoted string. The disadvantage is that you have to escape your backslashes. The big advantage however, is that you can then use Vim's escapes instead of literal control characters, which makes your config more readable and more copy/pasteable:

let @e = "\\\\'0\<down>"

Or if you prefer:

let @e = '\\' . "'0\<down>"
  • Thank you. I was scratching my head and had tried the usual variations of swapping single surrounding quotes for surrounding double quotes etc.
    – Kes
    May 27 at 12:45
  • 1
    @Kes I updated my answer with some more info about how and why you might want to do this with double quotes.
    – Rich
    May 27 at 13:01
  • Thanks @Rich, great answer, appreciated :)
    – Kes
    May 27 at 15:04
  • 1
    @Kes Glad I could help!
    – Rich
    May 27 at 15:26

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.