|
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 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -38,6 +38,7 @@ a remark is given. |
38 | 38 | 12. The sandbox |eval-sandbox| |
39 | 39 | 13. Textlock |textlock| |
40 | 40 | 14. Vim script library |vim-script-library| |
| 41 | +15. Clipboard providers |clipboard-providers| |
41 | 42 |
|
42 | 43 | Testing support is documented in |testing.txt|. |
43 | 44 | Profiling is documented at |profiling|. |
@@ -2247,7 +2248,14 @@ v:clipmethod The current method of accessing the clipboard that is being |
2247 | 2248 | x11 X11 selections are being used. |
2248 | 2249 | none The above methods are unavailable or |
2249 | 2250 | 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. |
2251 | 2259 |
|
2252 | 2260 | *v:cmdarg* *cmdarg-variable* |
2253 | 2261 | v:cmdarg This variable is used for two purposes: |
@@ -5266,5 +5274,111 @@ Usage: >vim |
5266 | 5274 | :call dist#vim9#Launch(<args>) |
5267 | 5275 | :Launch <app> <args>. |
5268 | 5276 | < |
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 | +< |
5270 | 5384 | vim:tw=78:ts=8:noet:ft=help:norl: |
0 commit comments