Re: [vim/vim] hlyank does not handle GUI autoselect via 'guioptions' P (Issue #20792)

h_east (Vim Github Repository) <[email protected]> Mon, 03 Aug 2026 06:39:00 -0700
Newsgroups gmane.editors.vim.devel
Message-ID <vim/vim/issues/20792/[email protected]>

----==_mimepart_6a7099f44184_e411687294e
Content-Type: text/plain; charset="UTF-8"

h-east left a comment (vim/vim#20792)

Checking a single flag is not enough, because the register autoselect uses
depends on both options.  Vim decides it in `clip_isautosel_star()` and
`clip_isautosel_plus()` (src/clipboard.c): while the GUI is running only
'guioptions' is looked at ("P" means the "+ register, otherwise "a" means the
"* register), and without the GUI it comes from 'clipboard' ("autoselect" for
"*, "autoselectplus" for "+).

So the guard can derive the register the same way:

```diff
-    # if clipboard has autoselect (default on linux) exiting from Visual with
-    # ESC generates bogus event and this highlights previous yank
-    if &clipboard =~ 'autoselect' && v:event.regname == "*" && v:event.visual
+    # if autoselect is used (default on linux) exiting from Visual with ESC
+    # generates bogus event and this highlights previous yank.  The register
+    # it uses is taken from 'guioptions' in the GUI and from 'clipboard'
+    # otherwise.
+    var autoselect: list<string> = []
+    if has('gui_running')
+      autoselect = &guioptions =~# 'P' ? ['+']
+        : &guioptions =~# 'a' ? ['*'] : []
+    else
+      if &clipboard =~# '\<autoselect\>'
+        autoselect->add('*')
+      endif
+      if &clipboard =~# '\<autoselectplus\>'
+        autoselect->add('+')
+      endif
+    endif
+    if v:event.visual && autoselect->index(v:event.regname) >= 0
       return
     endif
```

This also fixes a smaller problem in the current guard: `=~ 'autoselect'`
matches "autoselectplus" and "autoselectml" as well, so `set
clipboard=autoselectml` already suppresses the highlight for `"*y` today.
The comparisons use `=~#` so that 'ignorecase' cannot make "a" match the "A"
flag of 'guioptions', which is for the modeless selection only.

Note the trade-off does not go away: when autoselect is active for a register,
an explicit `"+y` (or `"*y`) from Visual mode is not highlighted either, since
the plugin cannot tell it apart from the bogus event.  That limitation exists
today for "* and this only extends it to "+.  @Arkissa, is that acceptable for
your setup, or is losing the highlight for an explicit yank the part you are
unsure about?

The missing '[ and '] update after a mouse selection looks like a separate
issue to me; it is worth its own report so it can be tracked separately.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/issues/20792#issuecomment-5167052405
You are receiving this because you are subscribed to this thread.

Message ID: <vim/vim/issues/20792/[email protected]>

-- 
-- 
You received this message from the "vim_dev" 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 the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/20792/5167052405%40github.com.

----==_mimepart_6a7099f44184_e411687294e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div style=3D"display: flex; flex-wrap: wrap; white-space: pre-wrap; align-=
items: center; "><img height=3D"20" width=3D"20" style=3D"border-radius:50%=
; margin-right: 4px;" decoding=3D"async" src=3D"https://avatars.githubuserc=
ontent.com/u/518808" /><strong>h-east</strong> left a comment <a href=3D"ht=
tps://github.com/vim/vim/issues/20792#issuecomment-5167052405">(vim/vim#207=
92)</a></div>
<p dir=3D"auto">Checking a single flag is not enough, because the register =
autoselect uses<br>
depends on both options.  Vim decides it in <code class=3D"notranslate">cli=
p_isautosel_star()</code> and<br>
<code class=3D"notranslate">clip_isautosel_plus()</code> (src/clipboard.c):=
 while the GUI is running only<br>
'guioptions' is looked at ("P" means the "+ register, otherwise "a" means t=
he<br>
"* register), and without the GUI it comes from 'clipboard' ("autoselect" f=
or<br>
"*, "autoselectplus" for "+).</p>
<p dir=3D"auto">So the guard can derive the register the same way:</p>
<div class=3D"highlight highlight-source-diff" dir=3D"auto"><pre class=3D"n=
otranslate"><span class=3D"pl-md"><span class=3D"pl-md">-</span>    # if cl=
ipboard has autoselect (default on linux) exiting from Visual with</span>
<span class=3D"pl-md"><span class=3D"pl-md">-</span>    # ESC generates bog=
us event and this highlights previous yank</span>
<span class=3D"pl-md"><span class=3D"pl-md">-</span>    if &amp;clipboard =
=3D~ 'autoselect' &amp;&amp; v:event.regname =3D=3D "*" &amp;&amp; v:event.=
visual</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    # if autoselect i=
s used (default on linux) exiting from Visual with ESC</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    # generates bogus=
 event and this highlights previous yank.  The register</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    # it uses is take=
n from 'guioptions' in the GUI and from 'clipboard'</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    # otherwise.</spa=
n>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    var autoselect: l=
ist&lt;string&gt; =3D []</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    if has('gui_runni=
ng')</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>      autoselect =3D =
&amp;guioptions =3D~# 'P' ? ['+']</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>        : &amp;guiopt=
ions =3D~# 'a' ? ['*'] : []</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    else</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>      if &amp;clipboa=
rd =3D~# '\&lt;autoselect\&gt;'</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>        autoselect-&g=
t;add('*')</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>      endif</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>      if &amp;clipboa=
rd =3D~# '\&lt;autoselectplus\&gt;'</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>        autoselect-&g=
t;add('+')</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>      endif</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    endif</span>
<span class=3D"pl-mi1"><span class=3D"pl-mi1">+</span>    if v:event.visual=
 &amp;&amp; autoselect-&gt;index(v:event.regname) &gt;=3D 0</span>
       return
     endif</pre></div>
<p dir=3D"auto">This also fixes a smaller problem in the current guard: <co=
de class=3D"notranslate">=3D~ 'autoselect'</code><br>
matches "autoselectplus" and "autoselectml" as well, so <code class=3D"notr=
anslate">set clipboard=3Dautoselectml</code> already suppresses the highlig=
ht for <code class=3D"notranslate">"*y</code> today.<br>
The comparisons use <code class=3D"notranslate">=3D~#</code> so that 'ignor=
ecase' cannot make "a" match the "A"<br>
flag of 'guioptions', which is for the modeless selection only.</p>
<p dir=3D"auto">Note the trade-off does not go away: when autoselect is act=
ive for a register,<br>
an explicit <code class=3D"notranslate">"+y</code> (or <code class=3D"notra=
nslate">"*y</code>) from Visual mode is not highlighted either, since<br>
the plugin cannot tell it apart from the bogus event.  That limitation exis=
ts<br>
today for "* and this only extends it to "+.  <a class=3D"user-mention notr=
anslate" data-hovercard-type=3D"user" data-hovercard-url=3D"/users/Arkissa/=
hovercard" data-octo-click=3D"hovercard-link-click" data-octo-dimensions=3D=
"link_type:self" href=3D"https://github.com/Arkissa">@Arkissa</a>, is that =
acceptable for<br>
your setup, or is losing the highlight for an explicit yank the part you ar=
e<br>
unsure about?</p>
<p dir=3D"auto">The missing '[ and '] update after a mouse selection looks =
like a separate<br>
issue to me; it is worth its own report so it can be tracked separately.</p=
>

<p style=3D"font-size:small;-webkit-text-size-adjust:none;color:#666;">&mda=
sh;<br />Reply to this email directly, <a href=3D"https://github.com/vim/vi=
m/issues/20792#issuecomment-5167052405">view it on GitHub</a>, or <a href=
=3D"https://github.com/notifications/unsubscribe-auth/ACY5DGG5YBEZWKIRYGBZK=
FL5ICIXJAVCNFSNUABEKJSXA33TNF2G64TZHM2DAOJZG42DQMR3JFZXG5LFHM2DSMRSHEYTCNBR=
GWQXMAQ">unsubscribe</a>.<br />Triage notifications, keep track of coding a=
gent tasks and review pull requests on the go with GitHub Mobile for <a hre=
f=3D"https://github.com/notifications/mobile/ios/ACY5DGEBM3PCAOCBAQREPM35IC=
IXJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJWG4YDKMRUGA22M=
4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ">iOS</a> and <a hre=
f=3D"https://github.com/notifications/mobile/android/ACY5DGA7ZYEYT7PA5KS6XJ=
D5ICIXJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJWG4YDKMRUG=
A22M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ">Android<=
/a>. Download it today!
<br />You are receiving this because you are subscribed to this thread.<img=
 src=3D"https://github.com/notifications/beacon/ACY5DGGTIF4ZWPH2GJXKUJ35ICI=
XJBFCNFSM6AAAAAC35RRWD2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3=
TUL5UWJTYAAAAACM726Z22M4TFMFZW63VKON2WE43DOJUWEZLE.gif" height=3D"1" width=
=3D"1" alt=3D"" /><span style=3D"color: transparent; font-size: 0; display:=
 none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: =
0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span>&lt;vim/vi=
m/issues/20792/5167052405</span><span>@</span><span>github</span><span>.</s=
pan><span>com&gt;</span></span></p>

<script type=3D"application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/vim/vim/issues/20792#issuecomment-5167052405"=
,
"url": "https://github.com/vim/vim/issues/20792#issuecomment-5167052405",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>

<p></p>

-- <br />
-- <br />
You received this message from the &quot;vim_dev&quot; maillist.<br />
Do not top-post! Type your reply below the text you are replying to.<br />
For more information, visit <a href=3D"http://www.vim.org/maillist.php">htt=
p://www.vim.org/maillist.php</a><br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;vim_dev&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">vim_dev+uns=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
vim_dev/vim/vim/issues/20792/5167052405%40github.com?utm_medium=3Demail&utm=
_source=3Dfooter">https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/=
20792/5167052405%40github.com</a>.<br />

----==_mimepart_6a7099f44184_e411687294e--