VIM edit only between specific line numbers

To edit content between specific line numbers use following expression in vim editor


In above expression add s after end line number.


Add # character at a starting of the line from line number 3 10 use following expression in vim:


To replace all foo’s with bar’s from line 3 to 10 use following expressin:


We can achieve same functionalities with sed expression also with following expressions:

$ sed -i "3,10s/^/#/g" inputFileName
$ sed -i "3,10s/foo/bar/g" inputFileName


By Sandeep Posted in sed, vim

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s