Wednesday, May 4, 2011

Re: Can you override the deletion register when pasting from visual mode?

On Wed, May 4, 2011 at 5:05 PM, Ben Schmidt
<mail_ben_schmidt@yahoo.com.au> wrote:
> On 4/05/11 11:35 PM, Andrew Neil wrote:
>>
>> Is there any way to prevent the default register from being clobbered
>> when using the paste command in visual mode?
>>
>> By default, when you use the `p` or `P` commands in visual mode, the
>> selected text overwrites the default register. Is there any way that
>> you can instruct Vim to write that text to another register?
>
> Not directly. To do that, you'd have to use separate delete and put
> commands. I suppose you could probably make a mapping. It could become a
> bit complicated dealing with edge cases, but I suppose you could make it
> work with a bit of effort. Maybe some wizard will chip in....

Here's a simple solution:

vnoremap p "_xP


But there's a problem with it: while `P` works fine in most cases, if
the visual selection is at the end of a line then you'd have to use
`p` instead. I think that one of the appealing things about making a
visual selection before pasting is that you don't have to worry about
whether to use `p` or `P` - it simply overwrites the selection with
the contents of the specified register.

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