7

I use :%s/'/"/g to replace all single quotes ' with double quotes " in a plain-text file

but when I want to put this command in a vim macro in .vimrc

let @r=':%s/'/"/g'

opening vim will give me this error

E114: Missing quote: "/g'

E15: Invalid expression: ':%s/'/"/g'

Press ENTER or type command to continue

I've tried not including the surrounding single-quotes let @r=:%s/'/"/g

it still gives me a similar error.

how do I include commands with single-quotes in a vim macro?

1 Answer 1

9

you add another single quote to escape your single quote inside your vim macro

let @r=':%s/''/"/g' 

from https://vim.fandom.com/wiki/Macros

if your register must itself contain single quote characters, you use a second single-quote character to escape it.

For example, if you want your register to contain "Vim's quote handling is a little tricky" you would type :let @a='"Vim''s quote handling is a little tricky"'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.