Tuesday, November 1, 2011

Re: replacing all characters in the current line?

On 02/11/11 05:21, Jose Caballero wrote:
> Hi,
>
> this happened to me today. 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).
> However, I was not able to make it work.
> I ended up doing something like :.s/=/-/g
>
> Is not really possible to replace all chars in the current line with a
> combination of 'g' and 'r' commands?
>
>
> Cheers,
> Jose
>

In Normal mode, IIUC g is not a complete command, but the first
character of quite a number of multikey commands, see :help g

To replace all characters in a line, I would use the :s[ubstitute]
command, as you ended up doing, or one of its variants:

To underline a (left-justified) heading:

yyp

then

:s/./-/g

The . range is optional, since the default for the :s command is the
current line. However the above method wouldn't work if there are hard
tabs in the line.


Best regards,
Tony.
--
Celestial navigation is based on the premise that the Earth is the
center of the universe. The premise is wrong, but the navigation
works. An incorrect model can be a useful tool.
-- Kelvin Throop III

--
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

No comments: