加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Vim(脚本) – 用作表达式时在字符串中引用

发布时间:2020-12-15 21:34:59 所属栏目:安全 来源:网络整理
导读:我正在尝试执行以下操作: :put = 'a string with "quotes"' 但我得到: Missing quote: 'a stringInvalid expression: 'a string 我可以解决这个问题: :let s:var = 'a "var"':put = s:var 通过阅读:h:put,我发现put,当跟着=时,需要一个表达式.我不知道
我正在尝试执行以下操作:

: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""

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读