Which Clipboard Backend Does Neovim Use When Both +clipboard and +xterm_clipboard Are Compiled?
0 reputation · 18 Jan 2023, 03:22 UTC
0 reputation · 18 Jan 2023, 03:22 UTC
Neovim can be built with both the +clipboard and +xterm_clipboard features. On Linux systems, the former typically maps to the X11 clipboard helper (e.g., xclip or xsel), while the latter is intended for terminal‑based clipboards such as wl-clipboard on Wayland. The clipboard option accepts values like unnamed, unnamedplus, or a comma‑separated list of backend names, but the official documentation does not specify a deterministic priority when both backends are present.
When a user runs set clipboard=unnamedplus in an X11 session, Neovim appears to use the X11 helper. In a Wayland session, however, the same setting may silently fall back to +xterm_clipboard if the X11 helper is missing, and this fallback is not guaranteed by the docs. If the chosen backend is unavailable, copy/paste operations fail without an explicit error, leading to inconsistent behaviour across sessions.
+clipboard over +xterm_clipboard when both are compiled, or is the order determined by the display server?33275 reputation · 18 Jan 2023, 14:31 UTC
When Neovim is built with both +clipboard and +xterm_clipboard, it prefers the +clipboard backend (the system‑clipboard integration) as long as that backend can be used at runtime.
+clipboard feature provides native OS clipboard access (X11 helpers like xclip/xsel on Linux, pbcopy/pbpaste on macOS, or the Windows clipboard).+xterm_clipboard feature is a terminal‑based fallback that works through escape sequences and is only consulted when the primary clipboard cannot be accessed.+clipboard hook first; if it reports success, that backend is used and +xterm_clipboard is ignored.If a functional clipboard provider (e.g., xsel, xclip, or wl-clipboard) is present and the appropriate display server variable (DISPLAY for X11 or WAYLAND_DISPLAY for Wayland) is set, Neovim will use +clipboard. When that provider is missing or the display variable is unset, the +clipboard hook fails at runtime and Neovim silently falls back to +xterm_clipboard. This fallback is not documented as a guarantee, which explains the observed inconsistency across sessions.
:version – confirm that both +clipboard and +xterm_clipboard appear in the feature list.:echo has('clipboard') and :echo has('xterm_clipboard'). Both should return 1 if the features were compiled.*y to yank a line into the * register, then paste outside Neovim (e.g., middle‑click or Ctrl+V). If the text appears, +clipboard is active.xsel or xclip on X11, wl-clipboard on Wayland) and that the corresponding environment variable (DISPLAY or WAYLAND_DISPLAY) is set. Re‑run the yank/paste test after installing the utility.Whether a functional clipboard provider is installed and accessible in the current session. If the provider is absent, Neovim will effectively ignore +clipboard and use +xterm_clipboard, so confirming the provider’s presence determines which backend is actually in use.
Use comments to ask for clarification. Post a solution as an answer.
33,275 reputation · 18 Jan 2023, 11:13 UTC
Neovim’s clipboard behavior is governed by a runtime provider system, not the compile-time +clipboard or +xterm_clipboard flags. The set clipboard=unnamedplus option only directs yanks to the + register; it does not select or prioritize a backend tool. To explicitly choose a clipboard implementation, define g:clipboard as a dictionary with copy and paste commands for both + and * registers, which bypasses automatic detection entirely. The reliability of the active backend can be confirmed with :checkhealth clipboard (or :checkhealth provider), which reports the detected tool and its usability. Note that tool-detection order and health-check naming vary across Neovim versions; inspecting $VIMRUNTIME/autoload/provider/clipboard.vim gives the current priority list for your build.