Was previously checking if the Wayland socket was executable. Now properly checks if it's readable.
universal-clipboard.nvim
A minimal Neovim plugin that automatically sets up sharing your system clipboard across multiple platforms. It addresses this issue:
Platform Differences: On macOS, Neovim appears to behave nicely with the system
clipboard. On others, not so much. External tools can help. For example, there’swl-copy/wl-pastefor Wayland orxclip/xselfor X11.
With universal-clipboard.nvim:
- If we detect an external clipboard tool (
wl-clipboard,xclip,xsel), we configure Neovim’sclipboardto use it. - Otherwise, we simply set
clipboardtounnamedpluswith no further configuration needed.
Installation
Using packer.nvim:
use({
"swaits/universal-clipboard.nvim",
config = function()
require("universal-clipboard").setup({
verbose = false, -- optional: set true to log detection details
})
end,
})
Or lazy.nvim:
{
"swaits/universal-clipboard.nvim",
opts = {
verbose = true, -- optional: set true to log detection details
},
}
Note
: If your Neovim lacks
+clipboard, make sure you have at least one ofwl-clipboard,xclip, orxselinstalled. Or you may customize the tools searched -- see below.
Default Options
{
-- If true, prints the chosen clipboard mode/tool at startup
verbose = false,
-- A table of tools to check, in order
tools = {
{
name = "wl-clipboard",
-- Either a string (the executable name) or a function returning boolean
detect = function()
local wayland_display = os.getenv("WAYLAND_DISPLAY")
local wayland_runtime = os.getenv("XDG_RUNTIME_DIR")
local socket_path = (wayland_runtime or "") .. "/" .. (wayland_display or "")
return (vim.fn.executable("wl-copy") == 1)
and (vim.fn.executable("wl-paste") == 1)
and wayland_display ~= ""
and (vim.fn.isdirectory(socket_path) == 1)
end,
commands = {
copy = "wl-copy",
paste = "wl-paste --no-newline",
},
},
{
name = "xclip",
detect = "xclip", -- Will check vim.fn.executable("xclip")
commands = {
copy = "xclip -selection clipboard",
paste = "xclip -selection clipboard -o",
},
},
{
name = "xsel",
detect = "xsel",
commands = {
copy = "xsel --clipboard --input",
paste = "xsel --clipboard --output",
},
},
},
}
Customizing Tools
If you want to add or remove tools, you can override the tools table in your
setup() call. For example:
require("universal-clipboard").setup({
verbose = true,
tools = {
-- If you only want xclip, for instance:
{
name = "xclip-only",
detect = "xclip",
commands = {
copy = "xclip -selection clipboard",
paste = "xclip -selection clipboard -o",
},
},
-- Or add more custom entries
},
})
The plugin will iterate over tools in order and select the first one that is
“available.”
Usage
Once installed, no additional steps are required. The plugin configures your clipboard on startup. Simply copy and paste in Neovim as usual.
Commands
-
:UniversalClipboardCheckPrints the currentclipboardconfiguration to the command line, showing whatvim.opt.clipboardandvim.g.clipboardare set to. -
:UniversalClipboardReinitRe-runs the detection logic, forcingverbosemode for that run to help troubleshoot. You normally do not need this, but it can be helpful if you install a new system tool after starting Neovim and want to see if it’s detected.