Tuesday, May 12, 2009

Inserting new lines with vim regular expressions

If you want to insert new lines with sed-style regular expressions in vim, the usual '\n' doesn't work. The trick is to produce a '^M' by hitting Ctrl-V,Ctrl-M. For example:


:%s/word /word^M/g


will replace the space after the word "word" with a line break across the whole file.

3 comments:

Lars Tesmer said...

Thank you! Already pulled my hairs out trying to figure out why \n\n wouldn't work! :D

Prashanth said...

Thanks!

izslpql99b said...

Needless to say, injection molding techniques have advanced lots Disposable Clear Shower Caps over the last few|the previous few|the previous couple of} years. Plastic molding is correct and holds the capability of producing virtually every type of parts utilizing plastics. It offers correct design due to the clamping pressure it offers.