On Dec 2, 9:58 pm, Harry Putnam <[email protected]> wrote:
> Can anyone show an example of how to do this:
>
> I want to wrap this:
>
> # [HP 101202_15:55:07
>   <selected text region here>
>   <selected text region here>
>   <selected text region here>
>   <selected text region here>
> # ]
>
> Around the selected text... that is, select some text and press a key
> combo ... voila... its no surrounded by:
>   # [HP 101202_15:55:07
>
>   # ]

Try this mapping in your .vimrc to map a key for this - I used F9

map <F9> :g/\%'</s/\%V\_.*\%V../# [HP 101202_15:55:07\r\0\r#]/<CR>

To explain (see :help pattern for more details)

:g/\%'</

Do this command on the line where the "start of visual selection" mark
is. This is necessary since if you just try the next bit as a simple
:%s command, the marks change as the substitution happens, so it
goes through and does more than one substitution since it find the
marks
more than once.

s/\%V\_.*\%V..

Search for as many characters including newlines that are in the
visual selection. The .. at the end is necessary since \%V is a
zero-width match.

/# [HP 101202_15:55:07\r\0\r#]/

Replace the found pattern (\0) with your text and newlines

<CR>

Equivalent to pressing Enter at the end if you entered the command
yourself.

----------------

I'm sure there's a better way to do this but I couldn't find it.
My first thought was to use the begin and end of visual selection
marks \%'< and \%'>, something like

:%s/\%'<.*\%'>/# [HP 101202_15:55:07\r\0\r#]/

but \%'> doesn't seem to work (just do a visual selection then
search for /\%'> and it fails) and I couldn't figure out why.

regards,
Geoff

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