Pasting from wrong register(?)

28 views
Skip to first unread message

Fabian Furger

unread,
Dec 30, 2016, 3:28:49 PM12/30/16
to v...@vim.org
Hi,

I frequently get bugged when pasting over a visually selected block of text and the default register contains the deleted text afterwards - chances are, I want to paste the same text multiple times.

A while ago I found a convenient map to get around that by replacing the content of the default register:

`vnoremap P p:call setreg('"', getreg('0'))<CR>`

That worked fine in terminal vim 7.3 (the version in Ubuntu 14.04 LTS) but doesn't seem to work on my own machine (terminal vim 8 on ArchLinux).
Checking with `:reg "`, I see that it does indeed contain the right content, but when pasting, it appears that the contents of the last selection register `"*` is used instead - I'd need to explicitly paste from the unnamed register `""p`.

Do I misunderstand something or am I doing something wrong?

Thanks in advance

Bee

unread,
Dec 30, 2016, 4:52:41 PM12/30/16
to vim_use, v...@vim.org
On Friday, December 30, 2016 at 12:28:49 PM UTC-8, Fabian Furger wrote:
> A while ago I found a convenient map to get around that by replacing the content of the default register:
>
> `vnoremap P p:call setreg('"', getreg('0'))<CR>`

Does the following work in both cases?

vnoremap P "0P

Fabian Furger

unread,
Dec 31, 2016, 3:18:39 AM12/31/16
to vim_use, v...@vim.org
On Friday, 30 December 2016 22:52:41 UTC+1, Bee wrote:
> Does the following work in both cases?
>
> vnoremap P "0P

Well, that kind of works even if it's not what I'm looking for - because after such a "replace" pasting with P in visual mode, I still lose the original content of the default register, so I can't do normal mode pasting (only visual mode).

I used to think that when not specifying the register, the default register is used - which apparently isn't the case like I described initially. Was this behavior changed at some point, is my thinking wrong, or may that be a bug?

Christian Brabandt

unread,
Dec 31, 2016, 5:55:06 AM12/31/16
to v...@vim.org
On Fr, 30 Dez 2016, Fabian Furger wrote:

> A while ago I found a convenient map to get around that by replacing the
> content of the default register:
>
> `vnoremap P p:call setreg('"', getreg('0'))<CR>`
>
> That worked fine in terminal vim 7.3 (the version in Ubuntu 14.04 LTS) but
> doesn't seem to work on my own machine (terminal vim 8 on ArchLinux).
> Checking with `:reg "`, I see that it does indeed contain the right content,
> but when pasting, it appears that the contents of the last selection register
> `"*` is used instead - I'd need to explicitly paste from the unnamed register
> `""p`.
>
> Do I misunderstand something or am I doing something wrong?

What is your 'clipboard' setting?

Best,
Christian
--
Objektivität: Alles hat zwei Seiten. Aber erst wenn man erkennt, daß
es drei sind, erfaßt man die Sache.
-- Heimito von Doderer

Fabian Furger

unread,
Dec 31, 2016, 12:27:27 PM12/31/16
to vim...@googlegroups.com, v...@vim.org
I'm setting clipboard to unnamed. I can't claim to fully understand yet how this (and related) options work so I played around a bit and found that it works when I have the `exclude:` part of the default clipboard value (not /etc/vimrc). That explains why it was working on the other machine (with the same configuration) - there was no X server to share a clipboard with.

To me, it seems like the best solution is to set the clipboard to `unnamedplus` and change the map to replace the `+`-register instead of the `"`-register - using the plus instead of the star register because the star register gets overwritten when selecting the text I'm trying to replace.

Thanks and a happy new year everyone!


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

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/FfKUA2Xgx_Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tony Mechelynck

unread,
Jan 1, 2017, 12:37:52 PM1/1/17
to vim...@googlegroups.com, v...@vim.org
On Sat, Dec 31, 2016 at 6:27 PM, Fabian Furger <myst...@gmail.com> wrote:
> I'm setting clipboard to unnamed. I can't claim to fully understand yet how
> this (and related) options work so I played around a bit and found that it
> works when I have the `exclude:` part of the default clipboard value (not
> /etc/vimrc). That explains why it was working on the other machine (with the
> same configuration) - there was no X server to share a clipboard with.
>
> To me, it seems like the best solution is to set the clipboard to
> `unnamedplus` and change the map to replace the `+`-register instead of the
> `"`-register - using the plus instead of the star register because the star
> register gets overwritten when selecting the text I'm trying to replace.
>
> Thanks and a happy new year everyone!
>
Happy New Year. With Vim, there is usually no "best" one-size-fits-all
solution. I use the value "exclude:cons\|linux" (which would come from
":set cb=exclude:cons\\\|linux") but I can't find where my vimrc sets
that value. When I want Vim to change the * and/or + register I do it
explicitly, otherwide I leave well enough alone.

Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages