Search and Replace in vim

To search and replace text in vim, change to command mode and you can do this;

%s/search/replace/gc

The above code will look for all the ‘search' text in the current buffer and change them to ‘replace' text. The ‘gc' tells vim to look though the entire buffer and confirm the change before it replaces the text, if you leave out the ‘c’ it will change without needing a user’s confirmation.

Advertisements
Posted in Uncategorized Tagged

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