How do I use PCRE-style regex in Vim without escaping every special character?
\v
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
640 results for "/pattern"
\v
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
:/pattern1/,/pattern2/
Ex command ranges in Vim are not limited to line numbers and marks — you can use /pattern/ as a range boundary to select lines between any two matching patter
* then :%s//new/g
Pressing searches for the word under the cursor, which also loads it into the search register.
:sort /regex/
The :sort /pattern/ command sorts lines by the text that appears after the first match of a pattern, not from the start of each line.
:helpgrep
:helpgrep {pattern} searches all installed Vim help files for a pattern and populates the quickfix list with every match.
:'<,'>s/\%Vpattern/replacement/g
Using \%V in a substitute pattern restricts matching to within the visual block area only, rather than the full lines.
\@>
Vim's \@> syntax creates an atomic group in a regular expression.
:%s/\(group\)/\1/g
Capture groups in Vim substitute let you match parts of a pattern and reuse them in the replacement.
\n in search, \r in replacement
Vim uses \n and \r differently depending on whether they appear in a search pattern or a replacement string, and mixing them up is a common source of confusion.
:try / :catch / :endtry
Vimscript has a structured exception handling system using :try, :catch, :finally, and :endtry.
/\cfoo
Vim's \c and \C flags let you force a search to be case-insensitive or case-sensitive on a per-search basis, regardless of your ignorecase and smartcase setting
/TODO/e
Most users know /pattern, but fewer use search offsets to control where the cursor lands after the match.
/\vTODO:\s*\zs.{-}\ze\s*($|#)
When TODO comments include prefixes, owners, or trailing metadata, a plain search often lands on the wrong part of the line.
/\cpattern
How it works By default, Vim searches are case-sensitive: /Hello will not match hello or HELLO.
matchlist()
matchlist({str}, {pattern}) runs a regex match and returns a list of all captured groups, making it the idiomatic way to extract structured data from strings in
vim.filetype.add()
vim.
:/start/,/end/d
Instead of specifying line numbers for Ex command ranges, you can use search patterns.
command-line #ex-commands #editing #search #ranges #command-line
\%>20c
The \%Nc, \%>Nc, and \%20c — match only after column 20 (i.
q/
How it works Vim keeps a history of all your search patterns.
:g/./t.\<CR>
The :global command can apply an Ex action to every line that matches a pattern.