From 1ab8bf1ce99e480f8bfbdfd34e3b6de6988c33ed Mon Sep 17 00:00:00 2001 From: WEI LI Date: Fri, 26 Sep 2025 23:24:27 +0800 Subject: [PATCH] fix: avoid osc52 fallback in tmux --- nvim/lua/config/options.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua index db081b9d..6bf8cd68 100644 --- a/nvim/lua/config/options.lua +++ b/nvim/lua/config/options.lua @@ -17,5 +17,40 @@ opt.timeoutlen = 400 opt.updatetime = 250 opt.completeopt = { "menu", "menuone", "noselect" } opt.clipboard = "unnamedplus" + +do + local function in_tmux() + local tmux_env = vim.env.TMUX + return type(tmux_env) == "string" and tmux_env ~= "" + end + + local function tmux_binary_available() + return vim.fn.executable("tmux") == 1 + end + + -- Older tmux releases (for example the version bundled with CentOS 7) do not + -- passthrough OSC 52 sequences. When Neovim detects an unavailable clipboard + -- provider it falls back to OSC 52, which results in the escape sequence + -- becoming visible in the editor instead of copying the text. Detect this + -- scenario and prefer the tmux load-buffer / save-buffer workflow instead of + -- relying on OSC 52. + if vim.g.clipboard == nil and in_tmux() and tmux_binary_available() then + local copy = "tmux load-buffer -w -" + local paste = "tmux save-buffer -" + + vim.g.clipboard = { + name = "tmux", + copy = { + ["+"] = copy, + ["*"] = copy, + }, + paste = { + ["+"] = paste, + ["*"] = paste, + }, + cache_enabled = false, + } + end +end opt.wrap = false opt.mouse = "a"