begin  quoting Andrew Lentvorski as of Sat, Jun 09, 2007 at 04:20:21PM -0700:
> Tracy R Reed wrote:
> >That seems strange to me but maybe it is a matter of familiarity. Search
> >and replace in vi is just regex. :%s/foo/bar is almost like instinct to
> >me and pretty intuitive.
> 
> It's not the regex that's the problem.  It's the auxiliary stuff.  Does 
> that syntax work for *all* vi flavors?

Every one that's built on ex. It's an ex/ed command, not a vi command.  :)

You can also use :0,$s/str1/str2/ (from line 0 to end of file...), as %
is just an alias of 0,$ for convenience's sake.

> I seem to recall that you forgot an extra slash as well as some silly 
> "global" flag or you only get 1 replacement per line.  Or, is it a vim 
> extension that you don't need it?

No, you should use the trailing /, and "g" if you want multiple replaces
per line -- this is actually a feature.

The "g" is required in sed as well. This is consistent behavior, not
silly.  It's old, established, widely used, and therefore, by
definition, intuitive. :-)

> I'm pretty sure we're talking:
> 
> :%s/foo/bar/g

Well, there's the more general form of "g/re/command", so you *could*
write ":g/foo/s/foo/bar/g" (globally find all lines that contain "foo"
and substitute "bar" for "foo" every place on that line), but folks
generaly prefer the shorter version.
 
> So, I need to remember the "all lines" operator "%" which is specific to 
> vi and has no discoverability.  I also need to remember the "g" global 
> flag which is specific to vi and has no discoverability.

Somewhere I have a quote that says something like "you can do anything
in vi with a single keystroke, if you can just remember that keystroke".
 
It's always been that vi basically requires a manual. Vim tries to build
in a lot of help, but I don't find that help to be, well, helpful -- I
*still* resort to dead-tree manuals, and/or google.

> The difference, for me, when I hit M-% to start the search and destroy 
> in emacs (which is the only reason I can actually remember the % in vi) 
> is that the system actually gives some prompting as to how to complete 
> the keystrokes to finish off the search-and-destroy.

Is there no way to do get it NOT to pester you with interactive dialog?
And confirming each and every substitution is not conducive for making
me a happy camper.  There are times when I want interactivity, and there
are times when I just want the tool to do what I tell it to and shut up.

-- 
I don't want to have an *experience* with my tools.
Stewart Stremler

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to