+++ date = "2023-01-15" tags = ["terminal","vim","clipboard"] title = "terminalのOSC52を使いclipboardを共有する" slug = "nvim" +++ terminalのOSC52という機能を使うと、ssh-sessionでもcopyしたものがsystemのclipboardに入ります。これらはosの互換性に関係ないため幅広く使えます。 ただし、clipboardの共有は、往々にしてセキュリティ問題があるため注意してください。 また、`tmux`ではできなかったので、`iterm2`の別タブで行いました。 iterm2の設定は、`General -> Selection -> Application ... access clipboard`です。 まず、`tty-copy`はコマンドです。`tty-copy text`というように使います。ssh先でもssh元のclipboardに入ります。 https://github.com/jirutka/tty-copy 次にvim-pluginです。 https://github.com/ojroques/vim-oscyank 例えば、`yy`で同時に`OSCYankReg`が実行されてsystemのclipboardに入れる設定です。 ``` Plug 'ojroques/vim-oscyank', {'branch': 'main'} "let g:oscyank_silent = v:true let g:oscyank_term = 'tmux' autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '+' | execute 'OSCYankReg +' | endif ``` ただ、tmux上で動作しないのがよくわからない。 tmuxには`set-option -g set-clipboard on`等を設定して、commandやpluginもtmuxに該当する項目があるのに動作しませんでした。