aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Heidelbacher <andrei.heidelbacher@gmail.com>2025-03-24 13:17:56 +0100
committerGitHub <noreply@github.com>2025-03-24 05:17:56 -0700
commit563051a53ef92349e3bfc0c94421094396a296bf (patch)
treec4e8f9304650ef817c393bdc88eb93e8cea82498
parentaf4231d4070c8d664b919f5466a827905881ef32 (diff)
downloadrneovim-563051a53ef92349e3bfc0c94421094396a296bf.tar.gz
rneovim-563051a53ef92349e3bfc0c94421094396a296bf.tar.bz2
rneovim-563051a53ef92349e3bfc0c94421094396a296bf.zip
feat(clipboard): support g:clipboard="osc52" #33021
Problem: Forcing Neovim to use OSC52 for the system clipboard should be simple and concise, since OSC52 is widely supported (Alacritty, Ghostty, iTerm2, WezTerm, Kitty, xterm, tmux, etc.) and is the most portable approach for syncing clipboards across SSH. Solution: Support g:clipboard="osc52".
-rw-r--r--runtime/autoload/provider/clipboard.vim21
-rw-r--r--runtime/doc/provider.txt3
2 files changed, 19 insertions, 5 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index 0bfd82f61d..abbd41d62a 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -59,6 +59,14 @@ function! s:split_cmd(cmd) abort
return (type(a:cmd) == v:t_string) ? split(a:cmd, " ") : a:cmd
endfunction
+function! s:set_osc52() abort
+ let s:copy['+'] = v:lua.require'vim.ui.clipboard.osc52'.copy('+')
+ let s:copy['*'] = v:lua.require'vim.ui.clipboard.osc52'.copy('*')
+ let s:paste['+'] = v:lua.require'vim.ui.clipboard.osc52'.paste('+')
+ let s:paste['*'] = v:lua.require'vim.ui.clipboard.osc52'.paste('*')
+ return 'OSC 52'
+endfunction
+
let s:cache_enabled = 1
let s:err = ''
@@ -69,6 +77,13 @@ endfunction
function! provider#clipboard#Executable() abort
" Setting g:clipboard to v:false explicitly opts-in to using the "builtin" clipboard providers below
if exists('g:clipboard') && g:clipboard isnot# v:false
+ if v:t_string ==# type(g:clipboard)
+ if 'osc52' == g:clipboard
+ " User opted-in to OSC 52 by manually setting g:clipboard.
+ return s:set_osc52()
+ endif
+ endif
+
if type({}) isnot# type(g:clipboard)
\ || type({}) isnot# type(get(g:clipboard, 'copy', v:null))
\ || type({}) isnot# type(get(g:clipboard, 'paste', v:null))
@@ -172,11 +187,7 @@ function! provider#clipboard#Executable() abort
elseif get(get(g:, 'termfeatures', {}), 'osc52') && &clipboard ==# ''
" Don't use OSC 52 when 'clipboard' is set. It can be slow and cause a lot
" of user prompts. Users can opt-in to it by setting g:clipboard manually.
- let s:copy['+'] = v:lua.require'vim.ui.clipboard.osc52'.copy('+')
- let s:copy['*'] = v:lua.require'vim.ui.clipboard.osc52'.copy('*')
- let s:paste['+'] = v:lua.require'vim.ui.clipboard.osc52'.paste('+')
- let s:paste['*'] = v:lua.require'vim.ui.clipboard.osc52'.paste('*')
- return 'OSC 52'
+ return s:set_osc52()
endif
let s:err = 'clipboard: No clipboard tool. :help clipboard'
diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt
index 24ec170319..38bf6281d3 100644
--- a/runtime/doc/provider.txt
+++ b/runtime/doc/provider.txt
@@ -277,6 +277,9 @@ To disable the automatic detection, set the "osc52" key of |g:termfeatures| to
To force Nvim to always use the OSC 52 provider you can use the following
|g:clipboard| definition: >lua
+ vim.g.clipboard = 'osc52'
+
+Which is equivalent to: >lua
vim.g.clipboard = {
name = 'OSC 52',
copy = {