Skip to content

Commit fcd3958

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.1.1972: No way to access the clipboard without X11/Wayland
Problem: No way to access the clipboard without X11/Wayland. Solution: Add the clipboard provider feature (Foxe Chen). closes: #18781 Signed-off-by: Foxe Chen <chen.foxe@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 98a0cbf commit fcd3958

28 files changed

+1348
-129
lines changed

runtime/doc/eval.txt

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 9.1. Last change: 2025 Dec 01
1+
*eval.txt* For Vim version 9.1. Last change: 2025 Dec 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -38,6 +38,7 @@ a remark is given.
3838
12. The sandbox |eval-sandbox|
3939
13. Textlock |textlock|
4040
14. Vim script library |vim-script-library|
41+
15. Clipboard providers |clipboard-providers|
4142

4243
Testing support is documented in |testing.txt|.
4344
Profiling is documented at |profiling|.
@@ -2247,7 +2248,14 @@ v:clipmethod The current method of accessing the clipboard that is being
22472248
x11 X11 selections are being used.
22482249
none The above methods are unavailable or
22492250
cannot be used.
2250-
See 'clipmethod' for more details.
2251+
If it is set to a value not in the above list, then a
2252+
clipboard provider with the given name is being used for the
2253+
clipboard functionality. See 'clipmethod' for more details.
2254+
2255+
*v:clipproviders*
2256+
v:clipproviders
2257+
A dictionary containing clipboard providers, see
2258+
|clipboard-providers| for more information.
22512259

22522260
*v:cmdarg* *cmdarg-variable*
22532261
v:cmdarg This variable is used for two purposes:
@@ -5266,5 +5274,111 @@ Usage: >vim
52665274
:call dist#vim9#Launch(<args>)
52675275
:Launch <app> <args>.
52685276
<
5269-
5277+
==============================================================================
5278+
15. Clipboard providers *clipboard-providers*
5279+
5280+
The clipboard provider feature allows the "+" |quoteplus| and "*" |quotestar|
5281+
registers to be overridden by custom Vimscript functions. There can be
5282+
multiple providers, and Vim chooses which one to use based on 'clipmethod'.
5283+
Despite the name, it does not use the 'clipboard' option and should be treated
5284+
separate from the clipboard functionality. It essentially overrides the
5285+
existing behaviour of the clipboard registers.
5286+
5287+
*clipboard-providers-no-clipboard*
5288+
If the |+clipboard| feature is not enabled, then the "+" and "*" registers
5289+
will not be enabled/available unless |v:clipmethod| is set to a provider. If
5290+
it is set to a provider, then the clipboard registers will be exposed despite
5291+
not having the |+clipboard| feature.
5292+
5293+
*clipboard-providers-plus*
5294+
If on a platform that only has the "*" register, then the "+" register will
5295+
only be available when |v:clipmethod| is set to a provider. If you want to
5296+
check if the "+" is available for use, it can be checked with: >
5297+
if has('unnamedplus')
5298+
<
5299+
*clipboard-providers-clipmethod*
5300+
To integrate the providers with Vim's clipboard functionality, the
5301+
'clipmethod' option is used on all platforms. The names of clipboard
5302+
providers should be put inside the option, and if Vim chooses it, then it
5303+
overrides the "+" and "*" registers. Note that the "+" and "*" will not be
5304+
saved in the viminfo at all.
5305+
5306+
*clipboard-providers-define*
5307+
To define a clipboard provider, the |v:clipproviders| vim variable is used. It
5308+
is a |dict| where each key is the clipboard provider name, and the value is
5309+
another |dict| declaring the "available", "copy", and "paste" callbacks: >vim
5310+
let v:clipproviders["myprovider"] = {
5311+
\ "available": function("Available"),
5312+
\ "paste": {
5313+
\ "+": function("Paste"),
5314+
\ "*": function("Paste")
5315+
\ },
5316+
\ "copy": {
5317+
\ "+": function("Copy"),
5318+
\ "*": function("Copy")
5319+
\ }
5320+
\ }
5321+
set clipmethod^=myprovider
5322+
<
5323+
Each callback can either be a name of a function in a string, a |Funcref|, or
5324+
a |lambda| expression.
5325+
5326+
With the exception of the "available" callback if a callback is not provided,
5327+
Vim will not invoke anything, and this is not an error.
5328+
5329+
*clipboard-providers-textlock*
5330+
In both the "paste" and "copy" callbacks, it is not allowed to change the
5331+
buffer text, see |textlock|.
5332+
5333+
*clipboard-providers-available*
5334+
The "available" callback is optional, does not take any arguments and should
5335+
return a |boolean| or non-zero number, which tells Vim if it is available
5336+
for use. If it is not, then Vim skips over it and tries the next 'clipmethod'
5337+
value. If the "available" callback is not provided, Vim assumes the provider
5338+
is always available for use (true).
5339+
5340+
*clipboard-providers-paste*
5341+
The "paste" callback takes the following arguments in the following order:
5342+
1. Name of the register being accessed, either "+" or "*".
5343+
5344+
It should return a |list| or |tuple| containing the following elements in
5345+
order:
5346+
1. Register type (and optional width) conforming to |setreg()|
5347+
2. A |list| of strings to return to Vim, each representing a line.
5348+
5349+
*clipboard-providers-copy*
5350+
The "copy" callback returns nothing and takes the following arguments in the
5351+
following order:
5352+
1. Name of the register being accessed, either "+" or "*".
5353+
2. Register type conforming to |getregtype()|
5354+
3. List of strings to use, each representing a line.
5355+
5356+
Below is a sample script that makes use of the clipboard provider feature: >vim
5357+
func Available()
5358+
return v:true
5359+
endfunc
5360+
5361+
func Copy(reg, type, str)
5362+
echom "Register: " .. a:reg
5363+
echom "Register type: " .. a:type
5364+
echom "Contents: " .. string(a:str)
5365+
endfunc
5366+
5367+
func Paste(reg)
5368+
return ("b40", ["this", "is", "the", a:reg, "register!"])
5369+
endfunc
5370+
5371+
let v:clipproviders["test"] = {
5372+
\ "available": function("Available"),
5373+
\ "copy": {
5374+
\ "+": function("Copy"),
5375+
\ "*": function("Copy")
5376+
\ },
5377+
\ "paste": {
5378+
\ "+": function("Paste"),
5379+
\ "*": function("Paste")
5380+
\ }
5381+
\ }
5382+
set clipmethod^=test
5383+
<
52705384
vim:tw=78:ts=8:noet:ft=help:norl:

runtime/doc/options.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Dec 09
1+
*options.txt* For Vim version 9.1. Last change: 2025 Dec 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1912,18 +1912,22 @@ A jump table for the options with a short description can be found at |Q_op|.
19121912
for VMS: "x11",
19131913
otherwise: "")
19141914
global
1915-
{only when the |+xterm_clipboard| or
1916-
|+wayland_clipboard| features are included}
1917-
Specifies which method of accessing the system clipboard is used,
1918-
depending on which method works first or is available. Supported
1919-
methods are:
1915+
{only when the |+xterm_clipboard|, |+wayland_clipboard|,
1916+
or |+eval| features are included}
1917+
Specifies which method of accessing the system clipboard (or clipboard
1918+
provider) is used. Methods are tried in the order given; the first
1919+
working method is used. Supported methods are:
19201920
wayland Wayland selections
19211921
x11 X11 selections
1922+
<name> Use a clipboard provider with the given name
19221923

19231924
Note: This option is ignored when either the GUI is running or if Vim
19241925
is run on a system without Wayland or X11 support, such as Windows or
1925-
macOS. The GUI or system way of accessing the clipboard is always
1926-
used instead.
1926+
macOS. The GUI or system way of accessing the clipboard is used
1927+
instead, meaning |v:clipmethod| will be set to "none". The
1928+
exception to this is the |clipboard-providers| feature, in which if
1929+
a clipboard provider is being used, then it will override the existing
1930+
clipboard functionality.
19271931

19281932
The option value is a list of comma separated items. The list is
19291933
parsed left to right in order, and the first method that Vim

runtime/doc/tags

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,7 @@ $quote eval.txt /*$quote*
14101410
+cindent various.txt /*+cindent*
14111411
+clientserver various.txt /*+clientserver*
14121412
+clipboard various.txt /*+clipboard*
1413+
+clipboard_provider various.txt /*+clipboard_provider*
14131414
+clipboard_working various.txt /*+clipboard_working*
14141415
+cmd editing.txt /*+cmd*
14151416
+cmdline_compl various.txt /*+cmdline_compl*
@@ -6692,6 +6693,15 @@ clipboard-autoselectml options.txt /*clipboard-autoselectml*
66926693
clipboard-autoselectplus options.txt /*clipboard-autoselectplus*
66936694
clipboard-exclude options.txt /*clipboard-exclude*
66946695
clipboard-html options.txt /*clipboard-html*
6696+
clipboard-providers eval.txt /*clipboard-providers*
6697+
clipboard-providers-available eval.txt /*clipboard-providers-available*
6698+
clipboard-providers-clipmethod eval.txt /*clipboard-providers-clipmethod*
6699+
clipboard-providers-copy eval.txt /*clipboard-providers-copy*
6700+
clipboard-providers-define eval.txt /*clipboard-providers-define*
6701+
clipboard-providers-no-clipboard eval.txt /*clipboard-providers-no-clipboard*
6702+
clipboard-providers-paste eval.txt /*clipboard-providers-paste*
6703+
clipboard-providers-plus eval.txt /*clipboard-providers-plus*
6704+
clipboard-providers-textlock eval.txt /*clipboard-providers-textlock*
66956705
clipboard-unnamed options.txt /*clipboard-unnamed*
66966706
clipboard-unnamedplus options.txt /*clipboard-unnamedplus*
66976707
clojure-indent indent.txt /*clojure-indent*
@@ -11258,6 +11268,7 @@ v:char eval.txt /*v:char*
1125811268
v:charconvert_from eval.txt /*v:charconvert_from*
1125911269
v:charconvert_to eval.txt /*v:charconvert_to*
1126011270
v:clipmethod eval.txt /*v:clipmethod*
11271+
v:clipproviders eval.txt /*v:clipproviders*
1126111272
v:cmdarg eval.txt /*v:cmdarg*
1126211273
v:cmdbang eval.txt /*v:cmdbang*
1126311274
v:collate eval.txt /*v:collate*

runtime/doc/various.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*various.txt* For Vim version 9.1. Last change: 2025 Nov 09
1+
*various.txt* For Vim version 9.1. Last change: 2025 Dec 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -379,6 +379,7 @@ T *+cindent* 'cindent', C indenting; Always enabled
379379
N *+clientserver* Unix and Win32: Remote invocation |clientserver|
380380
*+clipboard* |clipboard| support compiled-in
381381
*+clipboard_working* |clipboard| support compiled-in and working
382+
*+clipboard_provider* |clipboard-providers| support compiled-in
382383
T *+cmdline_compl* command line completion |cmdline-completion|
383384
T *+cmdline_hist* command line history |cmdline-history|
384385
T *+cmdline_info* 'showcmd' and 'ruler'; Always enabled since

runtime/doc/version9.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Dec 10
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Dec 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41653,6 +41653,8 @@ Other new features ~
4165341653

4165441654
- |items()| function now supports Blob.
4165541655

41656+
- The clipboard provider feature has been added |clipboard-providers|.
41657+
4165641658
*changed-9.2*
4165741659
Changed~
4165841660
-------
@@ -41907,6 +41909,8 @@ Options: ~
4190741909

4190841910
Vim Variables: ~
4190941911
|v:clipmethod| The current 'clipmethod'.
41912+
|v:clipproviders| A dictionary containing clipboard providers
41913+
configuration |clipboard-providers|.
4191041914
|v:stacktrace| The most recent caught exception.
4191141915
|v:t_enumvalue| Value of |enumvalue|.
4191241916
|v:t_enum| Value of |enum| type.

runtime/syntax/vim.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <dougkearns@gmail.com>
5-
" Last Change: 2025 Dec 04
5+
" Last Change: 2025 Dec 11
66
" Former Maintainer: Charles E. Campbell
77

88
" DO NOT CHANGE DIRECTLY.
@@ -166,7 +166,7 @@ syn keyword vimFuncName contained win_findbuf win_getid win_gettype win_gotoid w
166166
" Predefined variable names {{{2
167167
" GEN_SYN_VIM: vimVarName, START_STR='syn keyword vimVimVarName contained', END_STR=''
168168
syn keyword vimVimVarName contained count count1 prevcount errmsg warningmsg statusmsg shell_error this_session version lnum termresponse fname lang lc_time ctype charconvert_from charconvert_to fname_in fname_out fname_new fname_diff cmdarg foldstart foldend folddashes foldlevel progname servername dying exception throwpoint register cmdbang insertmode val key profiling fcs_reason fcs_choice beval_bufnr beval_winnr beval_winid beval_lnum beval_col beval_text scrollstart swapname swapchoice swapcommand char mouse_win mouse_winid mouse_lnum mouse_col operator searchforward hlsearch oldfiles windowid progpath completed_item option_new option_old option_oldlocal option_oldglobal option_command option_type errors false true none null numbermax numbermin numbersize
169-
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc vim_did_init
169+
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc vim_did_init clipproviders
170170

171171
"--- syntax here and above generated by runtime/syntax/generator/gen_syntax_vim.vim ---
172172

0 commit comments

Comments
 (0)