mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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".
This commit is contained in:
		 Andrei Heidelbacher
					Andrei Heidelbacher
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							af4231d407
						
					
				
				
					commit
					563051a53e
				
			| @@ -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' | ||||
|   | ||||
| @@ -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 = { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user