Permalink
Browse files

Add new behaviour to save all buffer on navigation (#144)

Summary: Added a new behaviour to tmux_navigator_save_on_switch which, when
set, causes all open and changed buffers to be written when navigating away
from a vim session.
  • Loading branch information...
1 parent 88f80ea commit 0c676d8cbc095462dc7b8bcbae54858783ad6caa @paymog paymog committed with Aug 31, 2016
Showing with 20 additions and 5 deletions.
  1. +12 −2 README.md
  2. +8 −3 plugin/tmux_navigator.vim
View
@@ -111,9 +111,19 @@ Left would be created with `nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>`.
##### Autosave on leave
- let g:tmux_navigator_save_on_switch = 1
+You can configure the plugin to write the current buffer, or all buffers, when navigating from Vim to tmux. This functionality is exposed via the `g:tmux_navigator_save_on_switch` variable, which can have either of the following values:
-This will execute the update command on leaving vim to a tmux pane. Default is Zero
+Value | Behavior
+------ | ------
+1 | `:update` (write the current buffer, but only if changed)
+2 | `:wall` (write all buffers)
+
+To enable this, add the following (with the desired value) to your ~/.vimrc:
+
+```vim
+" Write all buffers before navigating from Vim to tmux pane
+let g:tmux_navigator_save_on_switch = 2
+```
#### Tmux
@@ -67,10 +67,15 @@ function! s:TmuxAwareNavigate(direction)
" a) we're toggling between the last tmux pane;
" b) we tried switching windows in vim but it didn't have effect.
if tmux_last_pane || nr == winnr()
- if g:tmux_navigator_save_on_switch
+ if g:tmux_navigator_save_on_switch == 1
try
- update
- catch /^Vim\%((\a\+)\)\=:E32/
+ update " save the active buffer. See :help update
+ catch /^Vim\%((\a\+)\)\=:E32/ " catches the no file name error
+ endtry
+ elseif g:tmux_navigator_save_on_switch == 2
+ try
+ wall " save all the buffers. See :help wall
+ catch /^Vim\%((\a\+)\)\=:E141/ " catches the no file name error
endtry
endif
let args = 'select-pane -t ' . $TMUX_PANE . ' -' . tr(a:direction, 'phjkl', 'lLDUR')

0 comments on commit 0c676d8

Please sign in to comment.