Sunday, October 28, 2012

Re: surround a visual block with character(s)

On 09:47 Sun 28 Oct , Chris Lott wrote:
> What's the most efficient way to visually select a block of text and
> append/prepend a character or more?
>
> In other words, I often want convert this:
>
> blah blah foo foo
>
> to
>
> "blah blah foo foo"
>
> I assume there are plugins that help with this kind of thing, for
> which suggestions are welcome, but I'm curious how to do this most
> efficiently without them.
>
> c
> --
> Chris Lott <chris@chrislott.org>
>
> --
> 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

Hi Chris,

I don't recall if there is a vim operator which does this but you can
make a vmap:

vmap <Leader>" <esc>`>a"<esc>`<i"<esc>

You could also make an operator with

fun! Wrapper(arg)
let pos_b = getpos("'[")
let pos_e = getpos("']")
call cursor(pos_e[1:2])
normal! a"
call cursor(pos_b[1:2])
normal! i"
endfun
nmap <silent> <Leader>" :set opfunc=Wrapper<cr>g@

And you can use \"{motion} in normal mode (assuming that the <Leader> is
equal to "). You can also tweak the function so that it will operate
line wise. See :help g@, :help 'operatorfunc'.

regards,
Marcin

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