Tuesday, October 26, 2010

Re: Copying and replacing chars of a line through a regex

On Tue, 26 Oct 2010, Fernando Basso wrote:

> On Oct 26, 6:13 pm, Fernando Basso wrote:
>
>> Moreover, what if I wanted to make it paste above (in line 8)?
>
> Well, for that I came up with:
>
>
> :9global/^\w/t.|.-1substitute/./=/g
>
> However, I still don't understand where in that regex line it is
> implied to paste line 9 to line 10.

It's not entirely a regex:

:
9 [range] for :global
global/^\w/ " for each line matching /^\w/ - :help :global
t. " <-- here is the 'paste'

:t is a synonym for :copy.

:copy takes a mandatory {address} argument (in this case '.' = current
line for each line matched by the ':global'), and copies the lines given
by [range] (in this case, implied range of "the current line"?) to below
the address.

To copy line 9 in front of itself, you could do: :9g/^/t-1 (or :9t8 )

To copy lines matching /^\w/ in front of themselves: :g/^\w/t-1

...etc.

--
Best,
Ben

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