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