sponsor Vim development Vim logo Vim Book Ad

SuperSub : Enhanced Substitute Command

 script karma  Rating 5/2, Downloaded by 923  Comments, bugs, improvements  Vim wiki

created by
Phil Miller
 
script type
utility
 
description
SuperSub is an enhanced substitute command that can both replace multiple words in one line as well as multiple words in multiple lines.

Here are some examples:
My first name is Phil, my last name is Miller

Sure you could probably feed a simple regex into the standard substitute command for this one but you'll get the point

Issuing :S/Phil/John/Miller/Smith will change it to
My first name is John, my last name is Smith

Ok, so that's not very exciting so check out this. Let's say you have this piece of PHP code:
$contacts[1] = "Phil"

Simple right? Now you want five of them.

So you copy it five times:
$contacts[1] = "Phil"
$contacts[1] = "Phil"
$contacts[1] = "Phil"
$contacts[1] = "Phil"
$contacts[1] = "Phil"

Then you select all but the first row and issue this command:
:S/1/;2;3;4;5/Phil/;Jessica;Joel;Kaitlyn;PorkChop

And out comes this:
$contacts[1] = "Phil"
$contacts[2] = "Jessica"
$contacts[3] = "Joel"
$contacts[4] = "Phil"
$contacts[5] = "PorkChop"
 
install details
Just drop supersub.vim in your plugin directory.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
supersub.vim 0.1 2013-09-11 7.0 Phil Miller Initial upload
ip used for rating: 18.97.14.83

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github