Skip to content

Commit eb744dc

Browse files
committed
Add window size commands and tab navigation hotkeys
Implement hfull (_), vfull (|), sizeeq (=) for window size control in resize mode, and tabl (J) / tabr (K) for tab navigation across all modes. All new keycodes are configurable via g:winresizer_keycode_* variables. Closes #30 (partial: excludes close key already implemented in #29)
1 parent da9682e commit eb744dc

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ The key values are ASCII values. You can find a list of mappings [here](https://
7070
|g:winresizer_keycode_finish|13(`Enter`)|Fix and escape from window resize mode|
7171
|g:winresizer_keycode_cancel|113(`q`)|Cancel and quit window resize mode|
7272
|g:winresizer_keycode_close|120(`x`)|Close the current window (no-op if only one window remains)|
73+
|g:winresizer_keycode_hfull|95(`_`)|Maximize current window height (resize mode only)|
74+
|g:winresizer_keycode_vfull|124(`\|`)|Maximize current window width (resize mode only)|
75+
|g:winresizer_keycode_sizeeq|61(`=`)|Equalize all window sizes (resize mode only)|
76+
|g:winresizer_keycode_tabl|74(`J`)|Switch to previous tab (all modes)|
77+
|g:winresizer_keycode_tabr|75(`K`)|Switch to next tab (all modes)|
7378
|g:winresizer_keycode_split|115(`s`)|Split window horizontally (focus mode only)|
7479
|g:winresizer_keycode_vsplit|118(`v`)|Split window vertically (focus mode only)|
7580
|g:winresizer_keycode_flast|36(`$`)|Move focus to last window (focus mode only)|

plugin/winresizer.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ let s:default_keycode = {
8585
\ 'flast' : '36',
8686
\ 'fnext' : '119',
8787
\ 'fprev' : '87',
88+
\ 'hfull' : '95',
89+
\ 'vfull' : '124',
90+
\ 'sizeeq' : '61',
91+
\ 'tabl' : '74',
92+
\ 'tabr' : '75',
8893
\ 'finish':'13',
8994
\ 'cancel':'113',
9095
\ 'enter' :'13',
@@ -113,6 +118,11 @@ let g:winresizer_keycode_escape = get(g:, 'winresizer_keycode_escape', s:default
113118
let g:winresizer_keycode_enter = get(g:, 'winresizer_keycode_enter', s:default_keycode['enter'])
114119
let g:winresizer_keycode_mode = get(g:, 'winresizer_keycode_mode', s:default_keycode['mode'])
115120
let g:winresizer_keycode_close = get(g:, 'winresizer_keycode_close', 120)
121+
let g:winresizer_keycode_hfull = get(g:, 'winresizer_keycode_hfull', 95)
122+
let g:winresizer_keycode_vfull = get(g:, 'winresizer_keycode_vfull', 124)
123+
let g:winresizer_keycode_sizeeq = get(g:, 'winresizer_keycode_sizeeq', 61)
124+
let g:winresizer_keycode_tabl = get(g:, 'winresizer_keycode_tabl', 74)
125+
let g:winresizer_keycode_tabr = get(g:, 'winresizer_keycode_tabr', 75)
116126

117127
" if <ESC> key downed, finish resize mode
118128
let g:winresizer_finish_with_escape = get(g:, 'winresizer_finish_with_escape', 1)
@@ -133,6 +143,11 @@ let s:codeList = {
133143
\ 'enter' : g:winresizer_keycode_enter,
134144
\ 'mode' : g:winresizer_keycode_mode,
135145
\ 'close' : g:winresizer_keycode_close,
146+
\ 'hfull' : g:winresizer_keycode_hfull,
147+
\ 'vfull' : g:winresizer_keycode_vfull,
148+
\ 'sizeeq' : g:winresizer_keycode_sizeeq,
149+
\ 'tabl' : g:winresizer_keycode_tabl,
150+
\ 'tabr' : g:winresizer_keycode_tabr,
136151
\ 'num1' : '49',
137152
\ 'num2' : '50',
138153
\ 'num3' : '51',
@@ -168,6 +183,8 @@ fun! s:guiResizeCommands()
168183
\ 'up' : 'let &lines = &lines - ' . g:winresizer_horiz_resize,
169184
\ 'down' : 'let &lines = &lines + ' . g:winresizer_horiz_resize,
170185
\ 'cancel' : 'let &columns = ' . &columns . '|let &lines = ' . &lines . '|',
186+
\ 'tabl' : 'tabprevious',
187+
\ 'tabr' : 'tabnext',
171188
\}
172189

173190
return commands
@@ -185,6 +202,11 @@ fun! s:tuiResizeCommands()
185202
\ 'up' : ':resize ' . behavior['up'] . g:winresizer_horiz_resize,
186203
\ 'down' : ':resize ' . behavior['down'] . g:winresizer_horiz_resize,
187204
\ 'cancel' : winrestcmd(),
205+
\ 'hfull' : 'wincmd _',
206+
\ 'vfull' : 'wincmd |',
207+
\ 'sizeeq' : 'wincmd =',
208+
\ 'tabl' : 'tabprevious',
209+
\ 'tabr' : 'tabnext',
188210
\}
189211

190212
return commands
@@ -200,6 +222,8 @@ fun! s:moveCommands()
200222
\ 'up' : ":call winresizer#swapTo('up')",
201223
\ 'down' : ":call winresizer#swapTo('down')",
202224
\ 'cancel' : winrestcmd(),
225+
\ 'tabl' : 'tabprevious',
226+
\ 'tabr' : 'tabnext',
203227
\}
204228

205229
return commands
@@ -229,6 +253,8 @@ fun! s:focusCommands()
229253
\ 'flast' : '$ wincmd w',
230254
\ 'fnext' : 'wincmd w',
231255
\ 'fprev' : 'wincmd W',
256+
\ 'tabl' : 'tabprevious',
257+
\ 'tabr' : 'tabnext',
232258
\}
233259

234260
return commands
@@ -308,6 +334,16 @@ fun! s:startResize(commands)
308334
echohl WarningMsg | echo 'winresizer: ' . v:exception | echohl None
309335
endtry
310336
endif
337+
elseif c == s:codeList['hfull'] && has_key(l:commands, 'hfull') "_
338+
exe l:commands['hfull']
339+
elseif c == s:codeList['vfull'] && has_key(l:commands, 'vfull') "|
340+
exe l:commands['vfull']
341+
elseif c == s:codeList['sizeeq'] && has_key(l:commands, 'sizeeq') "=
342+
exe l:commands['sizeeq']
343+
elseif c == s:codeList['tabl'] && has_key(l:commands, 'tabl') "J
344+
exe l:commands['tabl']
345+
elseif c == s:codeList['tabr'] && has_key(l:commands, 'tabr') "K
346+
exe l:commands['tabr']
311347
elseif c == g:winresizer_keycode_cancel "q
312348
exe l:commands['cancel']
313349
redraw

test/winresizer.vader

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,80 @@ Execute (x hotkey continues resize loop when close fails):
320320
AssertEqual 2, winnr('$'), 'loop should continue after failed close'
321321
set hidden
322322
bdelete!
323+
324+
" ============================================================
325+
" Suite 8: Tab navigation hotkeys
326+
" ============================================================
327+
328+
Before (two tabs):
329+
tabnew
330+
" tabpagenr() == 2 (new tab is active)
331+
332+
After (cleanup):
333+
silent! tabclose
334+
silent! tabclose
335+
336+
Execute (tabl keycode config exists with default value J=74):
337+
AssertEqual 74, g:winresizer_keycode_tabl
338+
339+
Execute (tabr keycode config exists with default value K=75):
340+
AssertEqual 75, g:winresizer_keycode_tabr
341+
342+
Execute (J hotkey moves to previous tab):
343+
AssertEqual 2, tabpagenr(), 'should start on tab 2'
344+
call feedkeys("J\<CR>", 'L')
345+
execute 'WinResizerStartResize'
346+
AssertEqual 1, tabpagenr(), 'J should move to previous tab'
347+
348+
Execute (K hotkey moves to next tab):
349+
" Go to tab 1 first so K (tabnext) moves to tab 2
350+
tabfirst
351+
AssertEqual 1, tabpagenr(), 'should be on tab 1'
352+
call feedkeys("K\<CR>", 'L')
353+
execute 'WinResizerStartResize'
354+
AssertEqual 2, tabpagenr(), 'K should move to next tab'
355+
356+
" ============================================================
357+
" Suite 9: Window size commands
358+
" ============================================================
359+
360+
Before (reset to single window):
361+
only
362+
new
363+
only
364+
365+
After (cleanup):
366+
only
367+
368+
Execute (hfull keycode config exists with default value _=95):
369+
AssertEqual 95, g:winresizer_keycode_hfull
370+
371+
Execute (vfull keycode config exists with default value |=124):
372+
AssertEqual 124, g:winresizer_keycode_vfull
373+
374+
Execute (sizeeq keycode config exists with default value ==61):
375+
AssertEqual 61, g:winresizer_keycode_sizeeq
376+
377+
Execute (_ hotkey maximizes current window height):
378+
split
379+
resize 3
380+
let h_before = winheight(0)
381+
call feedkeys("_\<CR>", 'L')
382+
execute 'WinResizerStartResize'
383+
Assert winheight(0) > h_before, '_ should maximize window height'
384+
385+
Execute (| hotkey maximizes current window width):
386+
vsplit
387+
vertical resize 5
388+
let w_before = winwidth(0)
389+
call feedkeys("|\<CR>", 'L')
390+
execute 'WinResizerStartResize'
391+
Assert winwidth(0) > w_before, '| should maximize window width'
392+
393+
Execute (= hotkey equalizes window sizes):
394+
split
395+
resize 3
396+
let h_before = winheight(0)
397+
call feedkeys("=\<CR>", 'L')
398+
execute 'WinResizerStartResize'
399+
Assert winheight(0) > h_before, '= should equalize windows (height should grow from 3)'

0 commit comments

Comments
 (0)