From c17f7ea0d97f8c44deda9d476b22b49a0917c390 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 10 Dec 2020 18:07:24 +0000 Subject: [PATCH] Refactor tmux and set-clipboard detection Move logic to `autoload/tmux.vim` to detect the `vim` is being run inside a `tmux` sessions and if the `set-clipboard` option is enabled. This cleans up adding the optional `oscyank.vim` plugin when needed. --- autoload/tmux.vim | 12 ++++++++++++ plugin/mappings.vim | 2 +- vimrc | 4 +--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/autoload/tmux.vim b/autoload/tmux.vim index 910259e..d5901ef 100644 --- a/autoload/tmux.vim +++ b/autoload/tmux.vim @@ -1,5 +1,9 @@ let s:tmux_option = '@vim'.substitute($TMUX_PANE, '%', '\\%', 'g') +function! tmux#inSession() abort + return $TMUX !=# '' +endfunction + function! tmux#setNavigationFlag() abort call system('tmux set-window-option '.s:tmux_option.' 1') endfunction @@ -7,3 +11,11 @@ endfunction function! tmux#unsetNavigationFlag() abort call system('tmux set-window-option -u '.s:tmux_option) endfunction + +function! tmux#isSetClipboardOn() abort + if !tmux#inSession() + return 0 + endif + let l:set_clipboard = trim(system('tmux show-options -g set-clipboard')) + return l:set_clipboard ==# 'set-clipboard on' +endfunction diff --git a/plugin/mappings.vim b/plugin/mappings.vim index b0d4367..d8d848b 100644 --- a/plugin/mappings.vim +++ b/plugin/mappings.vim @@ -77,7 +77,7 @@ nnoremap tm :tabmove " Clear search highlights nnoremap :nohlsearch -if g:use_osc52 +if exists('loaded_oscyank') noremap y :Oscyank else " System clipboard yank/put diff --git a/vimrc b/vimrc index a5782de..88563fc 100644 --- a/vimrc +++ b/vimrc @@ -200,9 +200,7 @@ Pack 'jrozner/vim-antlr' " Plugins for remote integrations Pack 'greymd/oscyank.vim', {'type': 'opt'} -let g:use_osc52 = $TMUX !=# '' && -\ trim(system('tmux show-options -g set-clipboard')) ==# 'set-clipboard on' -if g:use_osc52 && isdirectory(expand('~/.vim/pack/minpac/opt/oscyank.vim')) +if tmux#isSetClipboardOn() packadd oscyank.vim endif