运算符 – 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

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...