From 7af8660355258052e9f4a161ebe16411ca23f467 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 16 Aug 2019 21:58:38 +0100 Subject: [PATCH] Also set tmux navigation flag on FocusGained Make using the `@vim$TMUX_PANE` window flag much more robust by unsetting it every time the zsh prompt is drawn and setting it again using a `FocusGained` `autocmd` in vim. This removes the need for the hacky check for zsh in the conditional defined in the `in_vim` variable. --- autoload/tmux.vim | 9 +++++++++ plugin/autocmds.vim | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 autoload/tmux.vim diff --git a/autoload/tmux.vim b/autoload/tmux.vim new file mode 100644 index 0000000..910259e --- /dev/null +++ b/autoload/tmux.vim @@ -0,0 +1,9 @@ +let s:tmux_option = '@vim'.substitute($TMUX_PANE, '%', '\\%', 'g') + +function! tmux#setNavigationFlag() abort + call system('tmux set-window-option '.s:tmux_option.' 1') +endfunction + +function! tmux#unsetNavigationFlag() abort + call system('tmux set-window-option -u '.s:tmux_option) +endfunction diff --git a/plugin/autocmds.vim b/plugin/autocmds.vim index 9f11c68..936af35 100644 --- a/plugin/autocmds.vim +++ b/plugin/autocmds.vim @@ -2,10 +2,10 @@ augroup benieAugroup autocmd! if $TMUX !=# '' - " Set tmux window option to detect when to change pane. - let s:tmux_option = '@vim'.substitute($TMUX_PANE, '%', '\\%', 'g') - call system('tmux set-window-option '.s:tmux_option.' 1') - au VimLeave * call system('tmux set-window-option -u '.s:tmux_option) + " [Un]set tmux window option to detect when to change pane. + call tmux#setNavigationFlag() + au FocusGained * call tmux#setNavigationFlag() + au VimLeave * call tmux#unsetNavigationFlag() endif " Reopening a file at last curson position