I can't for the life of me find an answer to this either on google or here or in the help files.
if "test.c" =~ "\.c"
At first I thought =~
mean ends in, but observe these results:
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
An explanation would be great. A link to a site attempting to decipher VimScript would be even better.
l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.
Vim's built-in scripting language, VimL. This language is also known as Vimscript. Depending on how you look at it, either VimL is an alternate name for Vimscript or Vimscript is an alternate name for VimL.
Vim script (aka Vimscript, or VimL) is a full feature scripting language, meaning it can solve almost any text processing problem.
Vim 9 has only a single big new feature: a new scripting language, Vim9script. The goal is to "drastically" improve the performance of Vim scripts, while also bringing the scripting language more into line with widely used languages such as JavaScript, TypeScript, and Java.
From the Vim documentation, it does a pattern match of the right operand (as a pattern) inside the left.
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
You might try your test cases again. I get, for example, inconsistent with yours:
echo ".pctestp" =~ "\.pc" 1
And double-quotes vs single quotes seem to affect how the backslash is interpreted:
echo "test.pc" =~ "\.c" 1 echo "test.pc" =~ '\.c' 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With