* Jose Caballero <jcaballero....@gmail.com> [2011-11-02 05:25]:
> I had a line like this one
> ===================
> and I wanted to replace all characters by '-',
> so I could have something like
> --------------------
>
> I thought I could do it by combining 'g' and 'r' as I understood 'g' is
> good to repeat the same command over all chars in a line (like guu or gUU).

sorry... different context of 'g' here.

you see, the letters 'g', 'q', and v' were not taken with vi
so they could be used for more.  while 'q' was used for
"macro recording" and the Vs ('v', 'V', and CTRL-V) were
then used for the three visual modes, the 'g' was simply used
as a prefix for more added command. no "global" in it at all.

the ":g/RE/cmd" command is to be read as
"go through all lines of the buffer,
tag each line which contains a match to the regular expression,
and then apply the following command to each line in turn."

a common command is 'p' for "print", so it read ":g/RE/p" in short.
by the way.. this is where the "grep command comes from..

and then ther is the 'p' *flag* to substitutions which means
"do not stop after the first match in each line,
but *continue* searching the line for more matches",
ie "global" for each line.

so the ":g" command typically goes "globally" through a
buffer while the 'p' flag makes substitution command go
"globally" through each line, looking for more matches.

> However, I was not able to make it work.
> I ended up doing something like  :.s/=/-/g

perfect! :)

nitpick: the '.' for "current line" can be left out.
so ":s/foo/bar/g" is the way to go.

> Is not really possible to replace all chars in the current
> line with a combination of 'g' and 'r' commands?

in short:  naaah. ;)

the 'r' command is a command of the visual mode -
and can only be used through a ":normal" command.
but that's a lot of hassle - and probably slow, too.

Sven

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to