Show Menu

Vim Regexp Cheat Sheet by

vim     regexp

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>­\)\@­<=)

Download the Vim Regexp Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/fievel_vim-regexp.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

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
          cVim Cheat Sheet

          More Cheat Sheets by fievel

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