RSS

[vim] Show and delete all lines that contain a certain pattern

04 Nov

1. Show all the lines that match a pattern, say PATTERN
:g/PATTERN

Use “g!” or “v” for negative matching. For example, to show all the lines that DO NOT match the pattern, PATTERN, use
:g!/PATTERN

2. Delete all the lines that contain the pattern, PATTERN
:g/PATTERN/d

Again, g! or v may be used for negative matching.

Application: You may use any of the following two commands to delete all the blank lines (including lines containing only whitespaces) from a file
:g/^\s*$/d
:v/\S/d

Reference: Vim Wiki.

About these ads
 
Leave a comment

Posted by on November 4, 2012 in vim

 

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 29 other followers

%d bloggers like this: