provider.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. *provider.txt* Nvim
  2. NVIM REFERENCE MANUAL by Thiago de Arruda
  3. Providers *provider*
  4. Nvim delegates some features to dynamic "providers". This document describes
  5. the providers and how to install them.
  6. *E319*
  7. Use of a feature requiring a missing provider is an error: >
  8. E319: No "foo" provider found. Run ":checkhealth provider"
  9. Run the |:checkhealth| command, and review the sections below.
  10. Type |gO| to see the table of contents.
  11. ==============================================================================
  12. Python integration *provider-python*
  13. Nvim supports Python |remote-plugin|s and the Vim legacy |python3| and
  14. |pythonx| interfaces (which are implemented as remote-plugins).
  15. Note: Only the Vim 7.3 legacy interface is supported, not later features such
  16. as |python-bindeval| (Vim 7.4); use the Nvim API instead. Python 2 is not
  17. supported.
  18. PYTHON QUICKSTART ~
  19. To use Python plugins, you need the "pynvim" module. Run |:checkhealth| to see
  20. if you already have it (some package managers install the module with Nvim
  21. itself).
  22. For Python 3 plugins:
  23. 1. Make sure Python 3.4+ is available in your $PATH.
  24. 2. Install the module (try "python" if "python3" is missing): >bash
  25. python3 -m pip install --user --upgrade pynvim
  26. The pip `--upgrade` flag ensures that you get the latest version even if
  27. a previous version was already installed.
  28. See also |python-virtualenv|.
  29. Note: The old "neovim" module was renamed to "pynvim".
  30. https://github.com/neovim/neovim/wiki/Following-HEAD#20181118
  31. If you run into problems, uninstall _both_ then install "pynvim" again: >bash
  32. python -m pip uninstall neovim pynvim
  33. python -m pip install --user --upgrade pynvim
  34. PYTHON PROVIDER CONFIGURATION ~
  35. *g:python3_host_prog*
  36. Command to start Python 3 (executable, not directory). Setting this makes
  37. startup faster. Useful for working with virtualenvs. Must be set before any
  38. check for has("python3"). >vim
  39. let g:python3_host_prog = '/path/to/python3'
  40. <
  41. *g:loaded_python3_provider*
  42. To disable Python 3 support: >vim
  43. let g:loaded_python3_provider = 0
  44. PYTHON VIRTUALENVS ~
  45. *python-virtualenv*
  46. If you plan to use per-project virtualenvs often, you should assign one
  47. virtualenv for Nvim and hard-code the interpreter path via
  48. |g:python3_host_prog| so that the "pynvim" package is not required
  49. for each virtualenv.
  50. Example using pyenv: >bash
  51. pyenv install 3.4.4
  52. pyenv virtualenv 3.4.4 py3nvim
  53. pyenv activate py3nvim
  54. python3 -m pip install pynvim
  55. pyenv which python # Note the path
  56. The last command reports the interpreter path, add it to your init.vim: >vim
  57. let g:python3_host_prog = '/path/to/py3nvim/bin/python'
  58. See also: https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim
  59. ==============================================================================
  60. Ruby integration *provider-ruby*
  61. Nvim supports Ruby |remote-plugin|s and the Vim legacy |ruby-vim| interface
  62. (which is itself implemented as a Nvim remote-plugin).
  63. RUBY QUICKSTART ~
  64. To use Ruby plugins with Nvim, install the latest "neovim" RubyGem: >bash
  65. gem install neovim
  66. Run |:checkhealth| to see if your system is up-to-date.
  67. RUBY PROVIDER CONFIGURATION ~
  68. *g:loaded_ruby_provider*
  69. To disable Ruby support: >vim
  70. let g:loaded_ruby_provider = 0
  71. <
  72. *g:ruby_host_prog*
  73. Command to start the Ruby host. By default this is "neovim-ruby-host". With
  74. project-local Ruby versions (via tools like RVM or rbenv) setting this can
  75. avoid the need to install the "neovim" gem in every project.
  76. To use an absolute path (e.g. to an rbenv installation): >vim
  77. let g:ruby_host_prog = '~/.rbenv/versions/2.4.1/bin/neovim-ruby-host'
  78. To use the RVM "system" Ruby installation: >vim
  79. let g:ruby_host_prog = 'rvm system do neovim-ruby-host'
  80. ==============================================================================
  81. Perl integration *provider-perl*
  82. Nvim supports Perl |remote-plugin|s on Unix platforms. Support for polling STDIN
  83. on MS-Windows is currently lacking from all known event loop implementations.
  84. The Vim legacy |perl-vim| interface is also supported (which is itself
  85. implemented as a Nvim remote-plugin).
  86. https://github.com/jacquesg/p5-Neovim-Ext
  87. Note: Only perl versions from 5.22 onward are supported.
  88. PERL QUICKSTART~
  89. To use perl remote-plugins with Nvim, install the "Neovim::Ext" cpan package: >bash
  90. cpanm -n Neovim::Ext
  91. Run |:checkhealth| to see if your system is up-to-date.
  92. PERL PROVIDER CONFIGURATION~
  93. *g:loaded_perl_provider*
  94. To disable Perl support: >vim
  95. :let g:loaded_perl_provider = 0
  96. <
  97. *g:perl_host_prog*
  98. Command to start the Perl executable. Must be set before any
  99. check for has("perl"). >vim
  100. let g:perl_host_prog = '/path/to/perl'
  101. <
  102. ==============================================================================
  103. Node.js integration *provider-nodejs*
  104. Nvim supports Node.js |remote-plugin|s.
  105. https://github.com/neovim/node-client/
  106. NODEJS QUICKSTART~
  107. To use javascript remote-plugins with Nvim, install the "neovim" npm package: >bash
  108. npm install -g neovim
  109. Run |:checkhealth| to see if your system is up-to-date.
  110. NODEJS PROVIDER CONFIGURATION~
  111. *g:loaded_node_provider*
  112. To disable Node.js support: >vim
  113. :let g:loaded_node_provider = 0
  114. <
  115. *g:node_host_prog*
  116. Command to start the Node.js host. Setting this makes startup faster.
  117. By default, Nvim searches for "neovim-node-host" using "npm root -g", which
  118. can be slow. To avoid this, set g:node_host_prog to the host path: >vim
  119. let g:node_host_prog = '/usr/local/bin/neovim-node-host'
  120. <
  121. ==============================================================================
  122. Clipboard integration *provider-clipboard* *clipboard*
  123. Nvim has no direct connection to the system clipboard. Instead it depends on
  124. a |provider| which transparently uses shell commands to communicate with the
  125. system clipboard or any other clipboard "backend".
  126. To ALWAYS use the clipboard for ALL operations (instead of interacting with
  127. the "+" and/or "*" registers explicitly): >vim
  128. set clipboard+=unnamedplus
  129. See 'clipboard' for details and options.
  130. *clipboard-tool*
  131. The presence of a working clipboard tool implicitly enables the '+' and "*"
  132. registers. Nvim looks for these clipboard tools, in order of priority:
  133. - |g:clipboard| (unless unset or `false`)
  134. - pbcopy, pbpaste (macOS)
  135. - wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
  136. - waycopy, waypaste (if $WAYLAND_DISPLAY is set)
  137. - xsel (if $DISPLAY is set)
  138. - xclip (if $DISPLAY is set)
  139. - lemonade (for SSH) https://github.com/pocke/lemonade
  140. - doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
  141. - *win32yank* (Windows)
  142. - putclip, getclip (Windows) https://cygwin.com/packages/summary/cygutils.html
  143. - clip, powershell (Windows) https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/clip
  144. - termux (via termux-clipboard-set, termux-clipboard-set)
  145. - tmux (if $TMUX is set)
  146. *g:clipboard*
  147. To configure a custom clipboard tool, set g:clipboard to a dictionary.
  148. For example this configuration integrates the tmux clipboard: >vim
  149. let g:clipboard = {
  150. \ 'name': 'myClipboard',
  151. \ 'copy': {
  152. \ '+': ['tmux', 'load-buffer', '-'],
  153. \ '*': ['tmux', 'load-buffer', '-'],
  154. \ },
  155. \ 'paste': {
  156. \ '+': ['tmux', 'save-buffer', '-'],
  157. \ '*': ['tmux', 'save-buffer', '-'],
  158. \ },
  159. \ 'cache_enabled': 1,
  160. \ }
  161. If "cache_enabled" is |TRUE| then when a selection is copied Nvim will cache
  162. the selection until the copy command process dies. When pasting, if the copy
  163. process has not died the cached selection is applied.
  164. g:clipboard can also use functions (see |lambda|) instead of strings.
  165. For example this configuration uses the g:foo variable as a fake clipboard:
  166. >vim
  167. let g:clipboard = {
  168. \ 'name': 'myClipboard',
  169. \ 'copy': {
  170. \ '+': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
  171. \ '*': {lines, regtype -> extend(g:, {'foo': [lines, regtype]}) },
  172. \ },
  173. \ 'paste': {
  174. \ '+': {-> get(g:, 'foo', [])},
  175. \ '*': {-> get(g:, 'foo', [])},
  176. \ },
  177. \ }
  178. The "copy" function stores a list of lines and the register type. The "paste"
  179. function returns the clipboard as a `[lines, regtype]` list, where `lines` is
  180. a list of lines and `regtype` is a register type conforming to |setreg()|.
  181. *clipboard-wsl*
  182. For Windows WSL, try this g:clipboard definition:
  183. >vim
  184. let g:clipboard = {
  185. \ 'name': 'WslClipboard',
  186. \ 'copy': {
  187. \ '+': 'clip.exe',
  188. \ '*': 'clip.exe',
  189. \ },
  190. \ 'paste': {
  191. \ '+': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
  192. \ '*': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
  193. \ },
  194. \ 'cache_enabled': 0,
  195. \ }
  196. <
  197. *clipboard-osc52*
  198. Nvim bundles a clipboard provider that allows copying to the system clipboard
  199. using OSC 52. OSC 52 is an Operating System Command control sequence that
  200. causes the terminal emulator to write to or read from the system clipboard.
  201. When Nvim is running in the |TUI|, it will automatically attempt to determine if
  202. the host terminal emulator supports OSC 52. If it does, then Nvim will use OSC
  203. 52 for copying and pasting if no other |clipboard-tool| is found and when
  204. 'clipboard' is unset.
  205. *g:termfeatures*
  206. To disable the automatic detection, set the "osc52" key of |g:termfeatures| to
  207. |v:false| in the |config| file. Example: >lua
  208. local termfeatures = vim.g.termfeatures or {}
  209. termfeatures.osc52 = false
  210. vim.g.termfeatures = termfeatures
  211. <
  212. To force Nvim to always use the OSC 52 provider you can use the following
  213. |g:clipboard| definition: >lua
  214. vim.g.clipboard = {
  215. name = 'OSC 52',
  216. copy = {
  217. ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
  218. ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
  219. },
  220. paste = {
  221. ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
  222. ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
  223. },
  224. }
  225. <
  226. Note that not all terminal emulators support reading from the system clipboard
  227. (and even for those that do, users should be aware of the security
  228. implications), so using OSC 52 for pasting may not be possible (and not
  229. necessary, because you can |paste| instead using your system paste function).
  230. Users may need to configure their terminal emulator to allow reading from the
  231. clipboard.
  232. <
  233. ==============================================================================
  234. Paste *provider-paste* *paste*
  235. "Paste" is a separate concept from |clipboard|: paste means "dump a bunch of
  236. text to the editor", whereas clipboard provides features like |quote+| to get
  237. and set the OS clipboard directly. For example, middle-click or CTRL-SHIFT-v
  238. (macOS: CMD-v) in your terminal is "paste", not "clipboard": the terminal
  239. application (Nvim) just gets a stream of text, it does not interact with the
  240. clipboard directly.
  241. *bracketed-paste-mode*
  242. Pasting in the |TUI| depends on the "bracketed paste" terminal capability,
  243. which allows terminal applications to distinguish between user input and
  244. pasted text. https://cirw.in/blog/bracketed-paste
  245. This works automatically if your terminal supports it.
  246. *ui-paste*
  247. GUIs can paste by calling |nvim_paste()|.
  248. PASTE BEHAVIOR ~
  249. Paste inserts text after the cursor. Lines break at <NL>, <CR>, and <CR><NL>.
  250. When pasting a huge amount of text, screen-updates are throttled and the
  251. message area shows a "..." pulse.
  252. In cmdline-mode only the first line is pasted, to avoid accidentally executing
  253. many commands. Use the |cmdline-window| if you really want to paste multiple
  254. lines to the cmdline.
  255. You can implement a custom paste handler by redefining |vim.paste()|.
  256. Example: >lua
  257. vim.paste = (function(lines, phase)
  258. vim.api.nvim_put(lines, 'c', true, true)
  259. end)
  260. ==============================================================================
  261. X11 selection mechanism *clipboard-x11* *x11-selection*
  262. X11 clipboard providers store text in "selections". Selections are owned by an
  263. application, so when the application gets closed, the selection text is lost.
  264. The contents of selections are held by the originating application (e.g., upon
  265. a copy), and only passed to another application when that other application
  266. requests them (e.g., upon a paste).
  267. *primary-selection* *quotestar* *quoteplus* *quote+*
  268. There are three documented X11 selections: PRIMARY, SECONDARY, and CLIPBOARD.
  269. CLIPBOARD is typically used in X11 applications for copy/paste operations
  270. (CTRL-c/CTRL-v), while PRIMARY is used for the last selected text, which is
  271. generally inserted with the middle mouse button.
  272. Nvim's X11 clipboard providers only use the PRIMARY and CLIPBOARD selections,
  273. for the "*" and "+" registers, respectively.
  274. ==============================================================================
  275. vim:tw=78:ts=8:noet:ft=help:norl: