微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运算符 – VimScript中的〜〜是什么意思?

我无法为我的生活找到一个答案,无论是在谷歌或这里或在帮助文件.
if "test.c" =~ "\.c"

起初我以为〜〜平均结束了,但是观察这些结果:

Command                               Result
echo "test.c" =~ "\.c"                1
echo "test.c" =~ "\.pc"               0
echo "test.pc" =~ "\.c"               1
echo "testc" =~ "\.c"                 1
echo "ctest" =~ "\.c"                 1
echo "ctestp" =~ "\.pc"               0
echo "pctestp" =~ "\.pc"              0
echo ".pctestp" =~ "\.pc"             0

一个很好的解释.指向尝试破译Vimscript的站点链接会更好.

From the Vim documentation,它在右边的操作数(作为一个模式)做一个模式匹配.

For strings there are two more items:

a =~ b      matches with
    a !~ b      does not match with

The left item “a” is used as a string. The right item “b” is used as a pattern,like what’s used for searching. Example:

:if str =~ " "
    :  echo "str contains a space"
    :endif
    :if str !~ '\.$'
    :  echo "str does not end in a full stop"
    :endif

您可能会再次尝试您的测试用例.我得到了,例如,与你的不一致:

echo ".pctestp" =~ "\.pc"             1

而双引号和单引号似乎会影响反斜杠的解释方式:

echo "test.pc" =~ "\.c"               1
echo "test.pc" =~ '\.c'               0

原文地址:https://www.jb51.cc/vim/386346.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐