Essential Regular Expressions for VIM Editor in Linux


vim editor
vim editor

VIM (Vi IMproved) is a programmers editor in linux. Current version 7.2.148 . It support multiple programming languages like PHP,HTML,CSS,Javascript etc … Its Regular expression performance is amazing. You can run through thousands of lines of database data and remove unwanted commas or You can quickly create an html link list of websites which contain a hunbered or thousand of website address. In VIM you can open files near 1GB .


Some Regular expressions are here


This is use to duplicate the entire row -> I used this in creating site links.  The 1 is the entire text in a row.

Other Some Important List.

:%s/^n{3}//               : delete blocks of 3 empty lines

:%s#s*r*$##               : same thing” deleting empty lines

:g/——-/.-10,.d          : Delete string & 10 previous lines

/([^0-9]|^)%.*%          : Search for absence of a digit or beginning of line

:%s#<[^>]+>##g             : delete html tags, leave text (non-greedy)

:g/^$/ d : delete all empty lines in a file

:g/^$/,/./-j : reduce multiple blank lines to a single blank

:10,20g/^/ mo 10 :reverse the order of the lines starting from the line 10 up to the line 20.

etc …

Also You can view a vim regularexpressions book in yahoo

gvim is the graphical version of vim editor. It has some more user friendly  buttons for basics operations.

Regex to remove HTML-Tags from a file using Sed

sed -e :a -e ‘s/<[^>]*>//g;/</N;//ba’ index.html

This regular expression removes all HTML-Tags from the file. It uses sed-line editor


Leave a Reply