diff --git a/plugin/tmux_navigator.vim b/plugin/tmux_navigator.vim index 7a91117..b6bc664 100644 --- a/plugin/tmux_navigator.vim +++ b/plugin/tmux_navigator.vim @@ -28,7 +28,7 @@ function! s:InTmuxSession() endfunction function! s:TmuxVimPaneIsZoomed() - return s:TmuxCommand("display-message -p '#{window_zoomed_flag}'") == 1 + return s:TmuxCommand(['display-message', '-p', '#{window_zoomed_flag}']) == 1 endfunction function! s:TmuxSocket() @@ -36,13 +36,24 @@ function! s:TmuxSocket() return split($TMUX, ',')[0] endfunction -function! s:TmuxCommand(args) - let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args - return system(cmd) +function! s:GetTmuxCommand(args) + return [s:TmuxOrTmateExecutable(), '-S', s:TmuxSocket()] + a:args endfunction +if has('nvim') + function! s:TmuxCommand(args) + return substitute(system(s:GetTmuxCommand(a:args)), '\n$', '', '') + endfunction +else + function! s:TmuxCommand(args) + " Vim does not support a list for `system()`. + let cmd = join(map(s:GetTmuxCommand(a:args), 'fnameescape(v:val)')) + return substitute(system(cmd), '\n$', '', '') + endfunction +endif + function! s:TmuxPaneCurrentCommand() - echo s:TmuxCommand("display-message -p '#{pane_current_command}'") + echo s:TmuxCommand(['display-message', '-p', '#{pane_current_command}']) endfunction command! TmuxPaneCurrentCommand call s:TmuxPaneCurrentCommand() @@ -94,8 +105,8 @@ function! s:TmuxAwareNavigate(direction) catch /^Vim\%((\a\+)\)\=:E141/ " catches the no file name error endtry endif - let args = 'select-pane -t ' . shellescape($TMUX_PANE) . ' -' . tr(a:direction, 'phjkl', 'lLDUR') - silent call s:TmuxCommand(args) + let args = ['select-pane', '-t', $TMUX_PANE, '-'.tr(a:direction, 'phjkl', 'lLDUR')] + call s:TmuxCommand(args) if s:NeedsVitalityRedraw() redraw! endif