vim/Q/How can I check whether vim or neovim will yank to the unnamedplus (system) clipboard?
How can I check whether vim or nvim will yank to the unnamedplus (system) clipboard?
Answer
- AI/Response
- Read the option: In Ex mode run
:set clipboard? (or :echo &clipboard). If you see clipboard=unnamedplus, yanks and deletes that target the unnamed register are also applied to the + register (the system clipboard on X11/Wayland/macOS when clipboard integration works). unnamed wires the unnamed register to * (primary selection on X11) instead of +. - Neovim from Lua:
vim.o.clipboard and vim.go.clipboard both reflect the global 'clipboard' value; :lua print(vim.o.clipboard) matches :set clipboard?. - Neovim — provider, not only a compile flag: nvim still uses
'clipboard' the same way, but it talks to the OS through a clipboard provider (e.g. pbcopy / pbpaste on macOS, xclip / xsel on X11, wl-copy / wl-paste on Wayland). Run :checkhealth and open the clipboard (or provider) section: failures there explain unnamedplus set in config while + never updates or paste-from-OS breaks. - Neovim quick probe in Lua:
:lua vim.fn.setreg('+', 'nvim-clipboard-test') then paste outside the editor; or :lua print(vim.fn.getreg('+')) after yy with unnamedplus — should echo the yanked text when the provider works. - Confirm the build can talk to the OS (Vim-centric):
:echo has('clipboard') and :version (+clipboard vs -clipboard) matter most for classic Vim; Neovim builds assume provider integration—trust :checkhealth plus the + register / OS paste checks above when diagnosing nvim. - Behavioral check: Yank a distinctive string with
yy (or visual then y), then inspect registers. Prefer :registers with no arguments (full list; press Space / j if -- More -- appears). :reg + means :reg then <Space> then + then Enter. The unnamed register’s name is a single ASCII double-quote — the Ex line is :reg " (space, one double-quote, Enter), which is easy to mistype; :echo string(vim.fn.getreg('"')) and :echo string(vim.fn.getreg('+')) in nvim always show something ('' means empty). To force text into the buffer: :put =vim.fn.getreg('"') then :put =vim.fn.getreg('+'). With unnamedplus, + should match the yank; confirm with Cmd+V / Ctrl+V outside the editor. - Contrast without unnamedplus: After a normal
yy, + may stay unchanged unless you yanked explicitly with "+y; compare :echo string(vim.fn.getreg('"')) vs getreg('+') (or the " / + lines in a full :registers dump) before and after one yank. - Troubleshooting — no visible echo from commands:
:set clipboard?, :lua print(...), and :echo has('clipboard') usually print a one-line echo in the message area (easy to miss when cmdheight is 1, another UI plugin steals echoes, or the line scrolls away). Try :set cmdheight=3, rerun :set clipboard?, or :echomsg 'clipboard=' .. &clipboard and then :messages. For Lua, :lua vim.notify(vim.inspect(vim.o.clipboard)) (with nvim-notify) or :put =execute('set clipboard?') drops text into the buffer so you cannot miss it. - Troubleshooting — checkhealth OK for pbcopy but visual yank skips macOS clipboard:
OK only means Neovim can invoke the clipboard tool. It does not set 'clipboard' to unnamedplus. With the default (empty clipboard), y in visual mode fills " / 0, not +, so Cmd+V outside the editor stays unchanged. Fix: set clipboard=unnamedplus / vim.o.clipboard = 'unnamedplus' in config, or yank explicitly with "+y. Right after a yank, use :echo string(vim.fn.getreg('"')) vs getreg('+') or a full :registers dump to see where the text went. - Troubleshooting — plain nvim OK, visual yank “doesn’t work” only under tmux: First verify inside tmux that
"+y updates + (:echo getreg('+')). If "+y works but y alone does not, you still need unnamedplus (or always "+y). If "+y also fails in tmux while checkhealth is green, run :messages after the yank (Neovim surfaces provider errors there), then test pbpaste from a shell in the same tmux pane after echo test | pbcopy — if the shell cannot round-trip pasteboard while attached to that tmux session, the editor inherits the same limitation (macOS sometimes tied tmux + pasteboard quirks; older setups used reattach-to-user-namespace). - Troubleshooting — single-register output looks empty: For
:reg + and :reg ", (1) :registers with no args is easier than single-register forms; watch for -- More -- and advance the pager. (2) :reg " must end with exactly one " (the register name); an extra " turns it into a different command / error. (3) Empty + may print no line for + in a short listing—use string(getreg(...)) or :put =... so emptiness shows as '' or a blank inserted line. (4) UI plugins (noice.nvim, etc.) sometimes reroute or auto-dismiss multiline :registers output—fall back to :echo string(...) / :put =... or :lua vim.print({ ... }). - Troubleshooting — registers output flashes then vanishes: Typical when noice.nvim (often with nvim-notify) shows
msg_show output in a notify / mini view that auto-dismisses. Mitigations: enable preset long_message_to_split so long output opens a split you can read; add a route sending event = "msg_show" (or kind = "echo") to view = "split"; raise views.notify.timeout (milliseconds) or false where supported; run :Noice / :Noice history to reopen message history after the popup closes; temporarily :Noice disable to confirm stock msgarea behavior. Bypass the UI entirely: :redir @a | silent registers | redir END then :new :put a (or :put =execute('registers')) so the dump lives in a buffer. - Vim help:
'clipboard' - Neovim docs:
clipboard option - Neovim clipboard integration (
:help clipboard)