I'm trying to do the following:
:put = 'a string with "quotes"'
But I get:
Missing quote: 'a string
Invalid expression: 'a string
I can get around this:
:let s:var = 'a "var"'
:put = s:var
By reading :h :put
, I found out that put
, when followed by =
, expects an expression. I don't know if this is the problem though, I thought strings were expressions (being values) like in many other languages.
Note this doesn't work either:
:put = "a string \"with quotes\""
The key to understanding this peculiarity can indeed be found at :help :put
:
You need to escape the '|' and '"' characters to prevent them from terminating the command.
Apparently, the unescaped "
would terminate the expression (and presumably start a comment). Therefore, escaping works:
:put = 'a string with \"quotes\"'
You can also circumvent this by using (doubled) single quotes:
:put ='a string with ''quotes'''
If you want to use double quotes, they all need escaping, and the inner once twice:
:put = \"a string with \\"quotes\\"\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With