我正在尝试执行以下操作:
:put = 'a string with "quotes"'
但我得到:
Missing quote: 'a string Invalid expression: 'a string
我可以解决这个问题:
:let s:var = 'a "var"' :put = s:var
通过阅读:h:put,我发现put,当跟着=时,需要一个表达式.我不知道这是不是问题,我认为字符串是表达式(是值),就像许多其他语言一样.
请注意,这也不起作用:
:put = "a string \"with quotes\""
解决方法
理解这种特性的关键确实可以在以下方面找到:help:put:
You need to escape the ‘|’ and ‘”‘
characters to prevent them from terminating the
command.
显然,未转义的“会终止表达(并且可能会发表评论).因此,逃避的作品:
:put = 'a string with \"quotes\"'
您还可以通过使用(加倍)单引号来避免这种情况:
:put ='a string with ''quotes'''
如果你想使用双引号,它们都需要转义,内部一次需要两次:
:put = \"a string with \\"quotes\\"\"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。