1- " Maps <M-h/j/k/l> to resize vim splits in the given direction. If there
2- " are no more windows in that direction, forwards the operation to tmux.
1+ " Maps <M-h/j/k/l> to resize vim splits in the given direction.
2+ " If the movement operation has no effect in Vim, it forwards the operation to
3+ " Tmux.
34
45if exists (" g:loaded_tmux_resizer" ) || &cp || v: version < 700
56 finish
@@ -22,7 +23,7 @@ if !exists("g:tmux_resizer_no_mappings")
2223endif
2324
2425function ! s: VimResize (direction)
25- " Resize toward given direction, like tmux
26+ " Resize Vim window toward given direction, like tmux
2627 let l: current_window_is_last_window = (winnr () == winnr (' $' ))
2728 if (a: direction == ' h' || a: direction == ' k' )
2829 let l: modifier = l: current_window_is_last_window ? ' +' : ' -'
@@ -37,6 +38,7 @@ function! s:VimResize(direction)
3738 let l: command = ' resize'
3839 let l: window_resize_count = g: tmux_resizer_resize_count
3940 endif
41+
4042 execute l: command . ' ' . l: modifier . l: window_resize_count . ' <CR>'
4143endfunction
4244
@@ -67,48 +69,36 @@ function! s:TmuxCommand(args)
6769 return system (cmd)
6870endfunction
6971
70- function ! s: TmuxResizerProcessList ()
71- echo s: TmuxCommand (" run-shell 'ps -o state= -o comm= -t ''''#{pane_tty}'''''" )
72- endfunction
73- command ! TmuxResizerProcessList call s: TmuxResizerProcessList ()
74-
75- let s: tmux_is_last_pane = 0
76- augroup tmux_resizer
77- au !
78- autocmd WinEnter * let s: tmux_is_last_pane = 0
79- augroup END
80-
8172function ! s: NeedsVitalityRedraw ()
8273 return exists (' g:loaded_vitality' ) && v: version < 704 && ! has (" patch481" )
8374endfunction
8475
85- function ! s: ShouldForwardResizeBackToTmux (tmux_last_pane, at_tab_page_edge)
86- return a: tmux_last_pane || a: at_tab_page_edge
87- endfunction
88-
8976function ! s: TmuxAwareResize (direction)
90- let nr = winnr ()
91- let tmux_last_pane = (a: direction == ' p' && s: tmux_is_last_pane )
92- if ! tmux_last_pane
93- call s: VimResize (a: direction )
94- endif
95- let at_tab_page_edge = (nr == winnr ())
96- " Forward the resize panes command to tmux if:
97- " a) we're toggling between the last tmux pane;
98- " b) we tried resizing windows in vim but it didn't have effect.
99- if s: ShouldForwardResizeBackToTmux (tmux_last_pane, at_tab_page_edge)
77+ let l: previous_window_width = winwidth (0 )
78+ let l: previous_window_height = winheight (0 )
79+
80+ " Attempt to resize Vim window
81+ call s: VimResize (a: direction )
82+
83+ " Call tmux if Vim window dimentions did not change
84+ if (l: previous_window_height == winheight (0 ) && l: previous_window_width == winwidth (0 ))
10085 if (a: direction == ' h' || a: direction == ' l' )
10186 let l: resize_count = g: tmux_resizer_vertical_resize_count
10287 else
10388 let l: resize_count = g: tmux_resizer_resize_count
10489 endif
10590 let args = ' resize-pane -' . tr (a: direction , ' hjkl' , ' LDUR' ) . ' ' . l: resize_count
91+
10692 silent call s: TmuxCommand (args )
93+
10794 if s: NeedsVitalityRedraw ()
10895 redraw !
10996 endif
110- let s: tmux_is_last_pane = 1
111- else
112- let s: tmux_is_last_pane = 0
11397 endif
11498endfunction
99+
100+ " For debugging
101+ function ! s: TmuxResizerProcessList ()
102+ echo s: TmuxCommand (" run-shell 'ps -o state= -o comm= -t ''''#{pane_tty}'''''" )
103+ endfunction
104+ command ! TmuxResizerProcessList call s: TmuxResizerProcessList ()
0 commit comments