robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Kevin Lockedocs: setting g:clipboard after provider init #377052a906bfad6

master
13.7 KiB368 linesraw
1*provider.txt*		Nvim
2
3
4		 NVIM REFERENCE MANUAL	  by Thiago de Arruda
5
6
7Providers					*provider*
8
9Nvim delegates some features to dynamic "providers". This document describes
10the providers and how to install them.
11						*E319*
12Use of a feature requiring a missing provider is an error: >
13
14    E319: No "foo" provider found. Run ":checkhealth vim.provider"
15
16Run the |:checkhealth| command, and review the sections below.
17
18				      Type |gO| to see the table of contents.
19
20==============================================================================
21Python integration				*provider-python*
22
23Nvim supports Python |remote-plugin|s and the Vim legacy |python3| and
24|pythonx| interfaces (which are implemented as remote-plugins).
25
26Note: Only the Vim 7.3 legacy interface is supported, not later features such
27as |python-bindeval| (Vim 7.4); use the Nvim API instead. Python 2 is not
28supported.
29
30
31PYTHON QUICKSTART ~
32
33To use Python plugins, you need the "pynvim" module. Run |:checkhealth| to see
34if you already have it (some package managers install the module with Nvim
35itself).
36
37For Python 3 plugins:
381. Make sure Python 3.9+ is available in your $PATH.
392. Install either uv (https://docs.astral.sh/uv/) or pipx
40   (https://pipx.pypa.io/stable/).
413. Install the module: >bash
42   pipx install pynvim
43   # or:
44   uv tool install --upgrade pynvim
45
46The `--upgrade` flag ensures that you get the latest version even if
47a previous version was already installed.
48
49See also |python-virtualenv|.
50
51PYTHON PROVIDER CONFIGURATION ~
52						*g:python3_host_prog*
53Command to start Python 3 (executable, not directory). Setting this makes
54startup faster. Useful for working with virtualenvs. Must be set before any
55check for has("python3").  >vim
56    let g:python3_host_prog = '/path/to/python3'
57<
58						*g:loaded_python3_provider*
59To disable Python 3 support: >vim
60    let g:loaded_python3_provider = 0
61
62
63PYTHON VIRTUALENVS ~
64						*python-virtualenv*
65Using pynvim 0.6.0+ installed via uv or pipx, Nvim will automatically detect
66pynvim even if other Python virtual environments are activated (technical
67note: via the "pynvim-python" global python tool).  For older pynvim (or older
68Neovim), where detection involved finding the first Python interpreter and
69checking if it could import pynvim, automatic detection would fail when
70another virtual environment is active.  Upgrading to the latest pynvim is the
71recommended solution to this; but if that's not an option, then you can set
72the variable |g:python3_host_prog| in `init.vim` to point to the full path to
73the Python interpreter where `pynvim` is installed, e.g.: >vim
74
75  let g:python3_host_prog = '/path/to/pynvim-venv/bin/python'
76<
77See also: https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim
78
79==============================================================================
80Ruby integration			      *provider-ruby*
81
82Nvim supports Ruby |remote-plugin|s and the Vim legacy |ruby-vim| interface
83(which is itself implemented as a Nvim remote-plugin).
84
85
86RUBY QUICKSTART ~
87
88To use Ruby plugins with Nvim, install the latest "neovim" RubyGem: >bash
89    gem install neovim
90
91Run |:checkhealth| to see if your system is up-to-date.
92
93
94RUBY PROVIDER CONFIGURATION ~
95						*g:loaded_ruby_provider*
96To disable Ruby support: >vim
97    let g:loaded_ruby_provider = 0
98<
99						*g:ruby_host_prog*
100Command to start the Ruby host. By default this is "neovim-ruby-host". With
101project-local Ruby versions (via tools like RVM or rbenv) setting this can
102avoid the need to install the "neovim" gem in every project.
103
104To use an absolute path (e.g. to an rbenv installation): >vim
105    let g:ruby_host_prog = '~/.rbenv/versions/2.4.1/bin/neovim-ruby-host'
106
107To use the RVM "system" Ruby installation: >vim
108    let g:ruby_host_prog = 'rvm system do neovim-ruby-host'
109
110==============================================================================
111Perl integration				*provider-perl*
112
113Nvim supports Perl |remote-plugin|s on Unix platforms. Support for polling STDIN
114on MS-Windows is currently lacking from all known event loop implementations.
115The Vim legacy |perl-vim| interface is also supported (which is itself
116implemented as a Nvim remote-plugin).
117https://github.com/jacquesg/p5-Neovim-Ext
118
119Note: Only perl versions from 5.22 onward are supported.
120
121PERL QUICKSTART~
122
123To use perl remote-plugins with Nvim, install the "Neovim::Ext" cpan package: >bash
124    cpanm -n Neovim::Ext
125
126Run |:checkhealth| to see if your system is up-to-date.
127
128
129PERL PROVIDER CONFIGURATION~
130						*g:loaded_perl_provider*
131To disable Perl support: >vim
132    :let g:loaded_perl_provider = 0
133<
134						*g:perl_host_prog*
135Command to start the Perl executable. Must be set before any
136check for has("perl").  >vim
137    let g:perl_host_prog = '/path/to/perl'
138<
139==============================================================================
140Node.js integration				*provider-nodejs*
141
142Nvim supports Node.js |remote-plugin|s.
143https://github.com/neovim/node-client/
144
145
146NODEJS QUICKSTART~
147
148To use javascript remote-plugins with Nvim, install the "neovim" npm package: >bash
149    npm install -g neovim
150
151Run |:checkhealth| to see if your system is up-to-date.
152
153
154NODEJS PROVIDER CONFIGURATION~
155						*g:loaded_node_provider*
156To disable Node.js support: >vim
157    :let g:loaded_node_provider = 0
158<
159						*g:node_host_prog*
160Command to start the Node.js host. Setting this makes startup faster.
161
162By default, Nvim searches for "neovim-node-host" using "npm root -g", which
163can be slow. To avoid this, set g:node_host_prog to the host path: >vim
164    let g:node_host_prog = '/usr/local/bin/neovim-node-host'
165<
166==============================================================================
167Clipboard integration			      *provider-clipboard* *clipboard*
168
169Nvim has no direct connection to the system clipboard. Instead it depends on
170a |provider| which transparently uses shell commands to communicate with the
171system clipboard or any other clipboard "backend".
172
173To ALWAYS use the clipboard for ALL operations (instead of interacting with
174the "+" and/or "*" registers explicitly): >vim
175    set clipboard+=unnamedplus
176
177See 'clipboard' for details and options.
178
179							      *clipboard-tool*
180The presence of a working clipboard tool implicitly enables the "+" and "*"
181registers. Nvim supports these clipboard tools, in order of priority:
182
183- |g:clipboard| : User override (if set to a dict or any string "name" below;
184  e.g. `g:clipboard="tmux"` forces tmux clipboard and skips auto-detection).
185- "pbcopy"    : pbcopy, pbpaste (macOS)
186- "wl-copy"   : wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
187- "wayclip"   : waycopy, waypaste (if $WAYLAND_DISPLAY is set)
188- "xsel"      : xsel (if $DISPLAY is set)
189- "xclip"     : xclip (if $DISPLAY is set)
190- "lemonade"  : lemonade (for SSH) https://github.com/pocke/lemonade
191- "doitclient": doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
192- "win32yank" : *win32yank* (Windows)
193- "putclip"   : putclip, getclip (Windows) https://cygwin.com/packages/summary/cygutils.html
194- "clip"      : clip, powershell (Windows) https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/clip
195- "termux"    : termux (via termux-clipboard-set, termux-clipboard-get)
196- "tmux"      : tmux (if $TMUX is set)
197- "osc52"     : |clipboard-osc52| (if supported by your terminal)
198
199								 *g:clipboard*
200To configure a custom clipboard tool, set `g:clipboard` to a string name (from
201the above |clipboard-tool| list), or dict (to explicitly specify the shell
202commands or |lambda| functions) before clipboard providers are initialized.
203
204Note: Clipboard providers are initialized by calling `has('clipboard')`, which
205is best avoided before setting `g:clipboard`. See "G:CLIPBOARD SETTINGS ARE NOT
206USED" in |faq-runtime| for workarounds.
207
208If "cache_enabled" is |TRUE| then when a selection is copied Nvim will cache
209the selection until the copy command process dies. When pasting, if the copy
210process has not died the cached selection is applied.
211
212The "copy" function stores a list of lines and the register type. The "paste"
213function returns the clipboard as a `[lines, regtype]` list, where `lines` is
214a list of lines and `regtype` is a register type conforming to |setreg()|.
215
216Example: set to "osc52" to force OSC52, skipping auto-detection of terminal
217support: >vim
218
219    let g:clipboard = 'osc52'
220
221Example: set to "wayclip" to force waycopy/waypaste: >vim
222
223    let g:clipboard = 'wayclip'
224
225Example: set to a dict which integrates the tmux clipboard: >vim
226
227    let g:clipboard = {
228      \   'name': 'myClipboard',
229      \   'copy': {
230      \      '+': ['tmux', 'load-buffer', '-'],
231      \      '*': ['tmux', 'load-buffer', '-'],
232      \    },
233      \   'paste': {
234      \      '+': ['tmux', 'save-buffer', '-'],
235      \      '*': ['tmux', 'save-buffer', '-'],
236      \   },
237      \   'cache_enabled': 1,
238      \ }
239
240
241Example: set to a dict which uses g:foo as a fake clipboard: >vim
242
243    let g:clipboard = {
244      \   'name': 'myClipboard',
245      \   'copy': {
246      \      '+': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
247      \      '*': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
248      \    },
249      \   'paste': {
250      \      '+': {-> get(g:, 'foo', [])},
251      \      '*': {-> get(g:, 'foo', [])},
252      \   },
253      \ }
254<
255							      *clipboard-wsl*
256For Windows WSL, try this g:clipboard definition:
257>vim
258    let g:clipboard = {
259      \   'name': 'WslClipboard',
260      \   'copy': {
261      \      '+': 'clip.exe',
262      \      '*': 'clip.exe',
263      \    },
264      \   'paste': {
265      \      '+': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
266      \      '*': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
267      \   },
268      \   'cache_enabled': 0,
269      \ }
270<
271							    *clipboard-osc52*
272Nvim bundles a clipboard provider that allows copying to the system clipboard
273using OSC 52, an "Operating System Command" control-sequence that causes the
274terminal emulator to write to or read from the system clipboard.
275
276When Nvim is running in the |TUI|, it automatically detects host terminal
277support for OSC 52. If successful, then Nvim will use OSC 52 for copying and
278pasting if no other |clipboard-tool| is found and when 'clipboard' is unset.
279NOTE: Using a terminal multiplexer (e.g. tmux) may inhibit automatic OSC 52
280support detection.
281
282							*g:termfeatures*
283To disable the automatic detection, set the "osc52" key of |g:termfeatures| to
284false early in your |config|. Example: >lua
285	local termfeatures = vim.g.termfeatures or {}
286	termfeatures.osc52 = false
287	vim.g.termfeatures = termfeatures
288<
289To force Nvim to use the OSC 52 provider you can set |g:clipboard|: >lua
290
291    vim.g.clipboard = 'osc52'
292
293Which is equivalent to: >lua
294    vim.g.clipboard = {
295      name = 'OSC 52',
296      copy = {
297        ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
298        ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
299      },
300      paste = {
301        ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
302        ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
303      },
304    }
305<
306Note: not all terminal emulators support reading from the system clipboard
307(and even for those that do, users should be aware of the security
308implications), so using OSC 52 for pasting may not be possible (and not
309necessary, because you can |paste| instead using your system paste function).
310Users may need to configure their terminal emulator to allow reading from the
311clipboard.
312<
313==============================================================================
314Paste							*provider-paste* *paste*
315
316"Paste" is a separate concept from |clipboard|: paste means "dump a bunch of
317text to the editor", whereas clipboard provides features like |quote+| to get
318and set the OS clipboard directly.  For example, middle-click or CTRL-SHIFT-v
319(macOS: CMD-v) in your terminal is "paste", not "clipboard": the terminal
320application (Nvim) just gets a stream of text, it does not interact with the
321clipboard directly.
322
323							*bracketed-paste-mode*
324Pasting in the |TUI| depends on the "bracketed paste" terminal capability,
325which allows terminal applications to distinguish between user input and
326pasted text.  https://cirw.in/blog/bracketed-paste
327This works automatically if your terminal supports it.
328
329							*ui-paste*
330GUIs can paste by calling |nvim_paste()|.
331
332PASTE BEHAVIOR ~
333
334Paste inserts text after the cursor.  Lines break at <NL>, <CR>, and <CR><NL>.
335When pasting a huge amount of text, screen-updates are throttled and the
336message area shows a "..." pulse.
337
338In cmdline-mode only the first line is pasted, to avoid accidentally executing
339many commands.  Use the |cmdline-window| if you really want to paste multiple
340lines to the cmdline.
341
342You can implement a custom paste handler by redefining |vim.paste()|.
343Example: >lua
344
345  vim.paste = (function(lines, phase)
346    vim.api.nvim_put(lines, 'c', true, true)
347  end)
348
349==============================================================================
350X11 selection mechanism			      *clipboard-x11* *x11-selection*
351
352X11 clipboard providers store text in "selections". Selections are owned by an
353application, so when the application gets closed, the selection text is lost.
354The contents of selections are held by the originating application (e.g., upon
355a copy), and only passed to another application when that other application
356requests them (e.g., upon a paste).
357
358				*primary-selection* *quotestar* *quoteplus* *quote+*
359
360There are three documented X11 selections: PRIMARY, SECONDARY, and CLIPBOARD.
361CLIPBOARD is typically used in X11 applications for copy/paste operations
362(CTRL-c/CTRL-v), while PRIMARY is used for the last selected text, which is
363generally inserted with the middle mouse button.
364
365Nvim's X11 clipboard providers only use the PRIMARY and CLIPBOARD selections,
366for the "*" and "+" registers, respectively.
367
368 vim:tw=78:ts=8:noet:ft=help:norl: