我无法为我的生活找到一个答案,无论是在谷歌或这里或在帮助文件.
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
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