Replace osc52yank.vim with autoload script

This commit is contained in:
Kenneth Benzie 2021-03-03 20:54:56 +00:00
parent cda1ca2a41
commit c5474821e3
3 changed files with 36 additions and 4 deletions

View File

@ -5,4 +5,4 @@ setlocal nospell
setlocal scrolloff=0
" Don't display line numbers
setlocal nonumber norelativenumber
setlocal nonumber norelativenumber signcolumn=no

34
autoload/osc52.vim Normal file
View File

@ -0,0 +1,34 @@
" Use the OSC 52 escape sequence to copy text to the local system clipboard
" when connected to a remote machine.
function! osc52#init()
augroup osc52
autocmd!
" Add an autocmd to run after text is yanked.
autocmd TextYankPost * call osc52#copy()
augroup END
" When connected to a remote session the + selection register is not
" available and the unnamed register is used instead. Add normal and visual
" mode mappings using the z register instead.
nnoremap <leader>y "zy
nnoremap <leader>Y "zY
vnoremap <leader>y "zy
vnoremap <leader>Y "zY
endfunction
function! osc52#copy()
" Only use OSC 52 when text is yanked with the z register.
if v:event['regname'] ==# 'z'
" Get the register contents and join the list into a string.
let l:content = join(v:event['regcontents'], "\n")
if v:event['regtype'] ==# 'V'
" Append a new line in linewise-visual mode to avoid surprises.
let l:content = l:content."\n"
endif
" Get the parent tty while being compatible with vim and neovim, originally
" from https://github.com/greymd/oscyank.vim
let l:tty = system('(tty || tty < /proc/$PPID/fd/0) 2> /dev/null | grep /dev/')
" Base 64 encode the content, and print OSC 52 escape sequence to the tty.
call system('base64 | xargs -0 printf "\\033]52;c;%s\\a" > '.l:tty, l:content)
endif
endfunction

4
vimrc
View File

@ -184,8 +184,6 @@ Pack 'joshglendenning/vim-caddyfile'
Pack 'kbenzie/vim-khr'
Pack 'jrozner/vim-antlr'
" Plugins for remote integrations
Pack 'greymd/oscyank.vim', {'type': 'opt'}
if tmux#isOption('set-clipboard', 'on')
packadd oscyank.vim
call osc52#init()
endif