How to replace from current line in Vim

The common command to search and replace text with confirmation in Vim is :%s/old/new/c. But, this begins the search and replace operation from the beginning of the file. There might be times when you want to begin search and replace from the current line.

The % in :%s/old/new/c is shortcut for 1,$, which means replace from first line to the last line. So, to search and replace from current line to end of file we can use .,$. This can be shortened to ,$. So, the command to search and replace from current line is :,$s/old/new/c

Tried with: Vim 7.4 and Ubuntu 14.04

Advertisements

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