@@ -7,6 +7,37 @@ if exists("g:loaded_tmux_navigator") || &cp || v:version < 700
7
7
endif
8
8
let g: loaded_tmux_navigator = 1
9
9
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
+
10
41
if ! exists (" g:tmux_navigator_save_on_switch" )
11
42
let g: tmux_navigator_save_on_switch = 0
12
43
endif
@@ -19,14 +50,6 @@ function! s:TmuxOrTmateExecutable()
19
50
return (match ($TMUX , ' tmate' ) != -1 ? ' tmate' : ' tmux' )
20
51
endfunction
21
52
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
-
30
53
function ! s: TmuxVimPaneIsZoomed ()
31
54
return s: TmuxCommand (" display-message -p '#{window_zoomed_flag}'" ) == 1
32
55
endfunction
@@ -52,15 +75,6 @@ augroup tmux_navigator
52
75
autocmd WinEnter * let s: tmux_is_last_pane = 0
53
76
augroup END
54
77
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
-
64
78
function ! s: NeedsVitalityRedraw ()
65
79
return exists (' g:loaded_vitality' ) && v: version < 704 && ! has (" patch481" )
66
80
endfunction
@@ -104,25 +118,3 @@ function! s:TmuxAwareNavigate(direction)
104
118
let s: tmux_is_last_pane = 0
105
119
endif
106
120
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