Show Menu
Cheatography

Vim Regexp Cheat Sheet by

Special char NOT requiring escape

\
Escape next character
^
Start-­of-line
$
End-of­-line
.
Any char
*
0 or more quantifier
~
Match last given substitute string
[...]
Match range
[^...]
Not range
&
In replac­ement: insert whole matched pattern
Interp­reted as regular expression operator without escaping (escape to match literal)

Special char requiring escape

\<
Beginning of a word
\>
End of word
\(...\)
Group
\|
Separate altern­ative
\_.
Any single char or end-of­-line
\+
1 or more quantifier
\=
0 or 1 quantifier
\?
or or 1 quantifier
\{n,m}
n to m quantifier
\{n}
n quantifier
\{n,}
at least n quantifier
\{,m}
0 to m quantifier
Interp­reted as regular expression operators only when escaped (otherwize will be interp­reted as literals).
 

Useful examples

:g/<pa­tte­rn>/d_
delete all lines matching pattern
s/^.*$\n//
delete empty lines
s/<­pat­ter­n>/new &/
Replace pattern by "new <whole matched patter­n>"
s/<­pat­ter­n>/­\=@a/
Replace pattern by content of register "­a"
s/<­pat­ter­n>//gn
Count nb occurence of pattern
 

Look around assertions

\@<=
positive look behind
\@<!
negative look behind
\@=
positive look ahead
\@!
negative look ahead
Must follow a group matching what to look behind or ahead (ex: \(<­pat­ter­n>­\)\@­<=)
   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          VI Editor Cheat Sheet
          Vim NERDTree Cheat Sheet
          Helix Keyboard Shortcuts

          More Cheat Sheets by fievel

          English Irregular Verbs Cheat Sheet
          Awesome Window Manager 3.x Cheat Sheet