Skip to main content
added 153 characters in body
Source Link
Kevin
  • 41.7k
  • 17
  • 91
  • 113

There are a couple ways to do this with :s, depending on how much typing you want to do. The easiest way is a simple search and replace:

:%s/find this line/replace with this/ 

The % will search the whole file and replace all occurrences.

If that's too much typing for you, you can yank the destination string (yy) and use the " (default) register, inserting it with Ctrl+r ":

:%s/<ctrl+r><">/replacement/ 

Or, if you have a copy of the replacement string, you can yank the two into separate registers with "ayy and "byy to yank into the a and b registers, respectively (you can use any letter for your registers). Then use Ctrl+r a and Ctrl+r b to paste them into the search and replace fields.

Not to one-up Bruce, but if you want to check lines before you replace them, just add the c option:

:%s/find this line/replace with this/c 

There are a couple ways to do this with :s, depending on how much typing you want to do. The easiest way is a simple search and replace:

:%s/find this line/replace with this/ 

The % will search the whole file and replace all occurrences.

If that's too much typing for you, you can yank the destination string (yy) and use the " (default) register, inserting it with Ctrl+r ":

:%s/<ctrl+r><">/replacement/ 

Or, if you have a copy of the replacement string, you can yank the two into separate registers with "ayy and "byy to yank into the a and b registers, respectively (you can use any letter for your registers). Then use Ctrl+r a and Ctrl+r b to paste them into the search and replace fields.

There are a couple ways to do this with :s, depending on how much typing you want to do. The easiest way is a simple search and replace:

:%s/find this line/replace with this/ 

The % will search the whole file and replace all occurrences.

If that's too much typing for you, you can yank the destination string (yy) and use the " (default) register, inserting it with Ctrl+r ":

:%s/<ctrl+r><">/replacement/ 

Or, if you have a copy of the replacement string, you can yank the two into separate registers with "ayy and "byy to yank into the a and b registers, respectively (you can use any letter for your registers). Then use Ctrl+r a and Ctrl+r b to paste them into the search and replace fields.

Not to one-up Bruce, but if you want to check lines before you replace them, just add the c option:

:%s/find this line/replace with this/c 
Source Link
Kevin
  • 41.7k
  • 17
  • 91
  • 113

There are a couple ways to do this with :s, depending on how much typing you want to do. The easiest way is a simple search and replace:

:%s/find this line/replace with this/ 

The % will search the whole file and replace all occurrences.

If that's too much typing for you, you can yank the destination string (yy) and use the " (default) register, inserting it with Ctrl+r ":

:%s/<ctrl+r><">/replacement/ 

Or, if you have a copy of the replacement string, you can yank the two into separate registers with "ayy and "byy to yank into the a and b registers, respectively (you can use any letter for your registers). Then use Ctrl+r a and Ctrl+r b to paste them into the search and replace fields.