Skip to content

Commit d28ccc4

Browse files
committed
Skip most of the plugin with empty $TMUX
Ref: #201 (comment)
1 parent d724094 commit d28ccc4

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

plugin/tmux_navigator.vim

+31-39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@ if exists("g:loaded_tmux_navigator") || &cp || v:version < 700
77
endif
88
let g:loaded_tmux_navigator = 1
99

10+
function! s:VimNavigate(direction)
11+
try
12+
execute 'wincmd ' . a:direction
13+
catch
14+
echohl ErrorMsg | echo 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits: wincmd k' | echohl None
15+
endtry
16+
endfunction
17+
18+
if !get(g:, 'tmux_navigator_no_mappings', 0)
19+
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
20+
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
21+
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
22+
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
23+
nnoremap <silent> <c-\> :TmuxNavigatePrevious<cr>
24+
endif
25+
26+
if empty($TMUX)
27+
command! TmuxNavigateLeft call s:VimNavigate('h')
28+
command! TmuxNavigateDown call s:VimNavigate('j')
29+
command! TmuxNavigateUp call s:VimNavigate('k')
30+
command! TmuxNavigateRight call s:VimNavigate('l')
31+
command! TmuxNavigatePrevious call s:VimNavigate('p')
32+
finish
33+
endif
34+
35+
command! TmuxNavigateLeft call s:TmuxAwareNavigate('h')
36+
command! TmuxNavigateDown call s:TmuxAwareNavigate('j')
37+
command! TmuxNavigateUp call s:TmuxAwareNavigate('k')
38+
command! TmuxNavigateRight call s:TmuxAwareNavigate('l')
39+
command! TmuxNavigatePrevious call s:TmuxAwareNavigate('p')
40+
1041
if !exists("g:tmux_navigator_save_on_switch")
1142
let g:tmux_navigator_save_on_switch = 0
1243
endif
@@ -19,14 +50,6 @@ function! s:TmuxOrTmateExecutable()
1950
return (match($TMUX, 'tmate') != -1 ? 'tmate' : 'tmux')
2051
endfunction
2152

22-
function! s:UseTmuxNavigatorMappings()
23-
return !get(g:, 'tmux_navigator_no_mappings', 0)
24-
endfunction
25-
26-
function! s:InTmuxSession()
27-
return $TMUX != ''
28-
endfunction
29-
3053
function! s:TmuxVimPaneIsZoomed()
3154
return s:TmuxCommand("display-message -p '#{window_zoomed_flag}'") == 1
3255
endfunction
@@ -52,15 +75,6 @@ augroup tmux_navigator
5275
autocmd WinEnter * let s:tmux_is_last_pane = 0
5376
augroup END
5477

55-
" Like `wincmd` but also change tmux panes instead of vim windows when needed.
56-
function! s:TmuxWinCmd(direction)
57-
if s:InTmuxSession()
58-
call s:TmuxAwareNavigate(a:direction)
59-
else
60-
call s:VimNavigate(a:direction)
61-
endif
62-
endfunction
63-
6478
function! s:NeedsVitalityRedraw()
6579
return exists('g:loaded_vitality') && v:version < 704 && !has("patch481")
6680
endfunction
@@ -104,25 +118,3 @@ function! s:TmuxAwareNavigate(direction)
104118
let s:tmux_is_last_pane = 0
105119
endif
106120
endfunction
107-
108-
function! s:VimNavigate(direction)
109-
try
110-
execute 'wincmd ' . a:direction
111-
catch
112-
echohl ErrorMsg | echo 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits: wincmd k' | echohl None
113-
endtry
114-
endfunction
115-
116-
command! TmuxNavigateLeft call s:TmuxWinCmd('h')
117-
command! TmuxNavigateDown call s:TmuxWinCmd('j')
118-
command! TmuxNavigateUp call s:TmuxWinCmd('k')
119-
command! TmuxNavigateRight call s:TmuxWinCmd('l')
120-
command! TmuxNavigatePrevious call s:TmuxWinCmd('p')
121-
122-
if s:UseTmuxNavigatorMappings()
123-
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
124-
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
125-
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
126-
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
127-
nnoremap <silent> <c-\> :TmuxNavigatePrevious<cr>
128-
endif

0 commit comments

Comments
 (0)