gpt4 book ai didi

operators - =~ 在 VimScript 中是什么意思?

转载 作者:行者123 更新时间:2023-12-03 11:06:50 25 4
gpt4 key购买 nike

我一生都无法在谷歌或这里或帮助文件中找到答案。

if "test.c" =~ "\.c"

一开始我以为 =~ mean 结束,但观察这些结果:
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

关于operators - =~ 在 VimScript 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9527654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com