mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(clipboard): enable OSC 52 clipboard provider by default (#26064)
Use the XTGETTCAP sequence to determine if the host terminal supports the OSC 52 sequence and, if it does, enable the OSC 52 clipboard provider by default. This is only done automatically when all of the following are true: 1. Nvim is running in the TUI 2. 'clipboard' is not set to unnamed or unnamedplus 3. g:clipboard is unset 4. Nvim is running in an SSH connection ($SSH_TTY is set) 5. Nvim is not running inside tmux ($TMUX is unset)
This commit is contained in:
37
runtime/plugin/osc52.lua
Normal file
37
runtime/plugin/osc52.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local tty = vim.iter(vim.api.nvim_list_uis()):any(function(ui)
|
||||
return ui.chan == 1 and ui.stdout_tty
|
||||
end)
|
||||
|
||||
if
|
||||
not tty
|
||||
or vim.g.clipboard ~= nil
|
||||
or vim.o.clipboard ~= ''
|
||||
or not os.getenv('SSH_TTY')
|
||||
or os.getenv('TMUX')
|
||||
then
|
||||
return
|
||||
end
|
||||
|
||||
require('vim.termcap').query('Ms', function(cap, seq)
|
||||
assert(cap == 'Ms')
|
||||
|
||||
-- If the terminal reports a sequence other than OSC 52 for the Ms capability
|
||||
-- then ignore it. We only support OSC 52 (for now)
|
||||
if not seq:match('^\027%]52') then
|
||||
return
|
||||
end
|
||||
|
||||
local osc52 = require('vim.ui.clipboard.osc52')
|
||||
|
||||
vim.g.clipboard = {
|
||||
name = 'OSC 52',
|
||||
copy = {
|
||||
['+'] = osc52.copy('+'),
|
||||
['*'] = osc52.copy('*'),
|
||||
},
|
||||
paste = {
|
||||
['+'] = osc52.paste('+'),
|
||||
['*'] = osc52.paste('*'),
|
||||
},
|
||||
}
|
||||
end)
|
||||
Reference in New Issue
Block a user