Fwd: clipboard=unnamedplus, v:register and yanks

62 views
Skip to first unread message

David Fishburn

unread,
Sep 25, 2011, 11:10:00 PM9/25/11
to vim_dev
Can anyone on the dev list comment on this one?

Thanks,
Dave

-------- Original Message --------
Subject: clipboard=unnamedplus, v:register and yanks
Date: Tue, 20 Sep 2011 08:25:55 -0400
From: David Fishburn <dfishb...@gmail.com>
To: vim_use <vim...@googlegroups.com>


Sorry if this shows up twice, used the wrong email account to send it the first time.


Vim 7.3.1-315

unnamedplus    A variant of "unnamed" flag which uses the clipboard
        register '+' (|quoteplus|) instead of register '*' for
        all operations except yank.  Yank shall copy the text
        into register '+' and also into '*' when "unnamed" is
        included.
        Only available with the |+X11| feature.
        Availability can be checked with: >
            if has('unnamedplus')

So if I read that correctly, when using unnamedplus all yank operations should use the '*' register and not the '+' register.

The register contents behaviour I see is also correct (will demonstrate below).

But what appears to be wrong is the value of v:register.

gvim -u NONE -U NONE --noplugin -N

Create a new buffer with the following lines:
1
2
3
4
5

:set clipboard=
:echo v:register
"

Go to first line, yy
:echo v:register
"
:echo @"
1

Go to 2nd line, "ayy
:echo v:register
a
:echo @"
2
:echo @a
2


Good.


:set clipboard=unnamedplus
:echo v:register
+
Go to 3rd line, yy
:echo v:register
+
:echo @"
3
:echo @+
Something else
:echo @*
Something else


Go to 4th line, dd
:echo v:register
+
:echo @"
4
:echo @+
4
:echo @*
4



So, referring back to the text again:
unnamedplus    A variant of "unnamed" flag which uses the clipboard
        register '+' (|quoteplus|) instead of register '*' for
        all operations except yank.  Yank shall copy the text
        into register '+' and also into '*' when "unnamed" is
        included.


If the + and * registers are not modified by yank operations, then shouldn't v:register = " when yanking text (3rd line in the above sample).  Since @+ is not modified at all.

Thanks,
Dave


Ingo Karkat

unread,
Sep 26, 2011, 8:41:17 AM9/26/11
to vim...@googlegroups.com

:help v:register mentions nothing about the *effective register*, only
the one supplied (and since 7.3.186, this considers the changed default
for the "unnamed" and "unnamedplus" values).
> v:register The name of the register supplied to the last normal
> mode command. Empty if none were supplied. |getreg()| |setreg()|

In my understanding, v:register is mainly necessary for custom
operations that work with registers, not for built-in commands like
yank. Is your inquiry about theoretical correctness, or do you have an
actual use case that is affected by this? In the latter case, I would
agree that v:register should account for the yank command. (But I don't
know how easy that would be to implement.)

-- regards, ingo

David Fishburn

unread,
Sep 26, 2011, 10:40:20 PM9/26/11
to vim...@googlegroups.com
...

>> If the + and * registers are not modified by yank operations, then
>> shouldn't v:register = " when yanking text (3rd line in the above
>> sample). Since @+ is not modified at all.
>
> :help v:register mentions nothing about the *effective register*, only
> the one supplied (and since 7.3.186, this considers the changed
> default for the "unnamed" and "unnamedplus" values).
>> v:register The name of the register supplied to the last normal
>> mode command. Empty if none were supplied. |getreg()| |setreg()|
>
> In my understanding, v:register is mainly necessary for custom
> operations that work with registers, not for built-in commands like
> yank. Is your inquiry about theoretical correctness, or do you have an
> actual use case that is affected by this? In the latter case, I would
> agree that v:register should account for the yank command. (But I
> don't know how easy that would be to implement.)

Then YankRing plugin
(http://www.vim.org/scripts/script.php?script_id=1234) relies upon
v:register to determine:
a) which register to capture changes from
b) which register to update when retrieving the next value (from the
ring) for pasting

Unfortunately, there really is no work around for it either.

I could choose "+yy, or in this case yy. There is no way to distinguish
those commands.

Dave

Tony Mechelynck

unread,
Sep 27, 2011, 12:36:38 AM9/27/11
to vim...@googlegroups.com, Ingo Karkat

That text is obsolete; it was changed in changeset b6471224d2af dated 9
February and again in changeset 3c7da93eb7f9 dated 10 May. The current
text is as follows:

> *v:register* *register-variable*
> v:register The name of the register in effect for the current normal mode
> command. If none is supplied it is the default register '"',
> unless 'clipboard' contains "unnamed" or "unnamedplus", then
> it is '*' or '+'.
> Also see |getreg()| and |setreg()|

Note that the text speaks of "the register in effect for the current
normal-mode command". When not in a normal-mode command (as with :echo)
the value is unspecified. A strict interpretation of the above text
implies that the only place where you could actually examine the value
of v:register and get a meaningful result would be in the {rhs} of a
Normal, Visual or Operator-Pending mapping (preferably with the <expr>
modifier). However if the meaning is extended to ex-commands which
accept a register argument it might have a value (inaccessible to the
user) during :put, :delete or :yank, and an accessible value during
execution of a user-command defined with the -register modifier.
Anywhere else than the two above cases (mapping and user-command) I
wouldn't rely on this variable having any meaningful value.

>
> In my understanding, v:register is mainly necessary for custom
> operations that work with registers, not for built-in commands like
> yank. Is your inquiry about theoretical correctness, or do you have an
> actual use case that is affected by this? In the latter case, I would
> agree that v:register should account for the yank command. (But I don't
> know how easy that would be to implement.)
>
> -- regards, ingo
>

Best regards,
Tony.
--
Champagne don't make me lazy.
Cocaine don't drive me crazy.
Ain't nobody's business but my own.
-- Taj Mahal

Ingo Karkat

unread,
Sep 27, 2011, 2:52:59 AM9/27/11
to vim...@googlegroups.com

True. There's no way to differentiate between an explicitly specified
unnamed register (""yy) and Vim defaulting to it (yy). For that, another
variable (e.g. v:register0, like the distinction between v:count and
v:count1) would be needed, or, as previously suggested, v:register

should account for the yank command.

While trying to implement the latter (which should be a matter of just
calling set_reg_var(0) in the special yank case), I've started to doubt
your interpretation of the "unnamedplus" help.

> ... uses the clipboard register '+' (|quoteplus|) instead of register


> '*' for all operations except yank. Yank shall copy the text into
> register '+' and also into '*' when "unnamed" is included.

Looking at the source and based on my own experiments, deletes _and_
yanks will go to register + with "unnamedplus". With
"unnamed,unnamedplus", yanks will _additionally_ go into register *, as
well as to register +. This also makes more sense to me from a usage
point of view than your interpretation.
However, this is at odds with the steps given in your initial message.
I'm currently on vacation and restricted to my wife's Ubuntu laptop, so
I'm not 100% confident about my own findings.

Could you please verify this once more? Maybe this isn't an issue at
all, just "user confused" :-)

-- regards, ingo

Reply all
Reply to author
Forward
0 new messages