begin quoting Andrew Lentvorski as of Wed, Jan 31, 2007 at 01:32:54PM -0800: > Ralph Shumaker wrote: > >I want to know how to use vi to do search and replace. Is there > >something easier to use than "help" to find out how? > > > >I want to replace all instances of > >"^[0-9][A-Z]" with > >"^[0-9] [A-Z]". > > You need to approach this sideways. A regular expression replacement > probably doesn't do what you need as you would have to capture the > matched characters, save them to a group, and then forward those groups > to the replacement expression. > > It might be possible, but it would be annoying. Oh, it's not that bad. It's remembering to escape the parens that's the most annoying part.
> I know this doesn't help you, but in Emacs I would do this with a macro. > > I would start a macro, search for the [0-9][A-Z], go to where the space > should be, insert the space, end the macro. Then I would execute the > macro until it failed. > > I'm sure that vi/vim has a similar facility, but you'd have to get one > of the vi bigots to tell you how. Pick your keystroke to use. I often use ^P, as I never use it otherwise. :map ^V^P 0a ^V^[/^[0-9][A-Z]^V^M /^[0-9][A-Z] Then ^P until done. (You could search first, but then you'd have to undo the change made by the last invocation as it failed to find a match, and then execute the rest of the macro in-place. By putting the search last, you can see that there are no more hits.) You can also "record" a macro, but I never bother to do that, as I almost inevitably end up doing inadvertent crap during the recording. You'd use the "q" command (:help q) to do that. Using the "q" command would probably match "the emacs way" better. -- Vi bigot. Stewart Stremler -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
