How do I use regular expressions without escaping special characters?
/\v pattern
The \v flag enables "very magic" mode in Vim regex, where most special characters work like standard regular expressions without needing backslashes.
/\v pattern
The \v flag enables "very magic" mode in Vim regex, where most special characters work like standard regular expressions without needing backslashes.
:%s/\(group\)/\1/g
Capture groups in Vim substitute let you match parts of a pattern and reuse them in the replacement.
:'<,'>s/old/new/g
After making a visual selection, you can run a substitute command that only affects the selected text.
:%s/pattern/\r/g
In the replacement part of :s, \r inserts a newline.
:%s/\(\w\+\)/\u\1/g
Vim provides case-conversion atoms in substitute replacements: \u uppercases the next character, \l lowercases it, \U uppercases until \e, and \L lowercases unt
n
After performing a search with / or ?, pressing n repeats the search in the same direction to find the next match.
/pattern\n next-line
Using \n in a Vim search pattern matches a newline character, allowing you to find patterns that cross line boundaries.
/pattern\@!
The \@! atom is a negative lookahead in Vim regex.
\@<=pattern
The \@<= atom is a positive lookbehind in Vim regex.
/pattern\ze followed
The \ze atom marks the end of the match, so you can match a pattern only when it appears before specific text.
:[{,]}s/old/new/g
By using the range [{,]}, you can limit a substitute command to the lines between the enclosing braces — effectively the current function or block.
:set hlsearch
The hlsearch option highlights all matches of the current search pattern throughout the file, making it easy to see where matches occur.
/{pattern}
The / command initiates a forward search in the file.
?{pattern}
The ? command searches backward from the cursor position.
:%s/\V literal.text/replacement/g
The \V (very nomagic) flag treats all characters as literal except for \.
`< and `>
The ` ` marks automatically track the boundaries of the last visual selection.
:cdo s/old/new/g
The :cdo command executes a command on every entry in the quickfix list.
:set scrollbind
The scrollbind option locks the scrolling of two or more windows together so they scroll in unison.
(
The ( motion moves the cursor backward to the start of the current or previous sentence.
`[ and `]
The ` [ ` and ] ` marks automatically track the boundaries of the last changed or yanked text.