Friday, September 13, 2013

Insert a text at pattern using regexp in VIM

Say one is editing a text file in vim:


blah-blah234qqqqqqqqqq
blah-blah345234qqqqqqqqqq

and would like to insert a space at position after blah-blah345[digits] in each line.

One could use a following search-n-replace expression with help of regexp:

:%s/\(blah-blah\d\+\)/\1  /g

\( \) - for group selection
\1 - for first group selected
\d - for digit

No comments:

Post a Comment