Viml matching
From wikinotes
Regex
NOTE:
When using regex you probably want to use
'literal-strings'
instead of"strings"
.Documentation
vim regex docs http://vimdoc.sourceforge.net/htmldoc/pattern.html#pattern vim regex 101 http://vimregex.com/ substitution
" equiv to /s/{2}/{3}/g substitute("/path/to/project/src/main/java/com/willpittman/package/MyClass.java", '^.*src/\(main\|test\)/java/', "", "g")comparison
if match("string", "^str") " regex match '\v...' " all non char ranges have special meaning '\V...' " only '\' has special meaning if "abc" =~ '^ab' " regex match if "ABC" =~? '^ab' " case-insensitive regex if "ABC" ==? '^ab' " case-sensitive regex (regardless of :set (no)ignorecase) if "ABC" ==# '^ab' " case-insensitive regex (regardless of :set (no)ignorecase) " .. there are more ..lookahead/lookbehind
" lookahead (exclude vs include) syntax 'apple \(orange\)\@!' " match apple (consume apple), only if orange does not follows it syntax 'apple \(orange\)\@=' " match apple (consume apple), only if orange follows it " lookbehind (exclude vs include) syntax '\(apple\)\@<! orange' " match orange (consume orange), only if not preceeded by apple syntax '\(apple\)\@<= orange' " match orange (consume orange), only if preceeded by applelookaround
lookaround allows you to match/ignore strings. They do not become a part of the resulting match.
{1}\zs{2}
match {2} is preceeded by {1}. {1} is not part of the match{1}\ze{2}
match {1} is followed by {2}. {2} is not part of the match%s/myFunction(\zs.*\ze)/foo/
See https://vi.stackexchange.com/questions/3036/is-lookaround-possible-in-vims-regex-system wed by {2}. {2} is not part of the match
%s/myFunction(\zs.*\ze)/foo/
See https://vi.stackexchange.com/questions/3036/is-lookaround-possible-in-vims-regex-system