Tmux-style window resizing in vim?

407 views
Skip to first unread message

Jonathan del Strother

unread,
Oct 26, 2012, 6:58:47 AM10/26/12
to v...@vim.org
I'm a big fan of tmux's window management - it seems a lot more
intuitive than vim's, which has never quite clicked with me and I'm
not sure why.

Tmux resizes as if you were pushing/pulling at the border of the
current window in the direction that you're trying to resize, via the
hjkl keys. So if I have two windows stacked on top of each other, and
the top pane has focus, hitting <C-b>j pushes the split downwards,
growing the top window & shrinking the bottom. If the bottom pane had
focus, <C-b>j would pull the split downwards, resulting in the same
effect.
By contrast, in vim, <C-w>+ increases the height of the current
window. Which I can see the logic of, but the key locations (+/- vs
</> for the vertical/horizontal resizing) frustrate me, and if you
just remap it to hjkl then it feels like it ought to be using the same
resize behaviour as tmux.

Other niceties from tmux are that you can press <C-b>jjjjj to carry on
resizing, whereas in vim you'd have to use
<C-w>+<C-w>+<C-w>+<C-w>+<C-w>+. I'd also love to have something like
<C-b>spacebar which cycles through a series of preset layouts
(vertical split with a small sidebar, equal horizontal split, etc
etc).


Are there any plugins that tackle something like this? Or any
suggestions on learning to cope?

Thanks
-Jonathan

Jonathan del Strother

unread,
Oct 26, 2012, 7:01:27 AM10/26/12
to v...@vim.org
On 26 October 2012 11:58, Jonathan del Strother <mail...@steelskies.com> wrote:
> I'm a big fan of tmux's window management - it seems a lot more
> intuitive than vim's, which has never quite clicked with me and I'm
> not sure why.
>
> Tmux resizes as if you were pushing/pulling at the border of the
> current window in the direction that you're trying to resize, via the
> hjkl keys. So if I have two windows stacked on top of each other, and
> the top pane has focus, hitting <C-b>j pushes the split downwards,
> growing the top window & shrinking the bottom. If the bottom pane had
> focus, <C-b>j would pull the split downwards, resulting in the same
> effect.

... damn. I've just realized that I have a slightly custom tmux.conf
to achieve that, along the lines of
https://github.com/sjl/dotfiles/blob/master/tmux/tmux.conf#L50

Marco

unread,
Oct 26, 2012, 7:25:10 AM10/26/12
to vim...@googlegroups.com
2012-10-26 Jonathan del Strother:

> By contrast, in vim, <C-w>+ increases the height of the current
> window. Which I can see the logic of, but the key locations (+/- vs
> </> for the vertical/horizontal resizing) frustrate me, and if you
> just remap it to hjkl then it feels like it ought to be using the same
> resize behaviour as tmux.

Yes, I find that confusing, too. There is probably a solution, but
since it's a minor issue I never bothered to fix it.

> Other niceties from tmux are that you can press <C-b>jjjjj to carry on
> resizing, whereas in vim you'd have to use
> <C-w>+<C-w>+<C-w>+<C-w>+<C-w>+.

I have set the following in my .vimrc

map <silent> <A-h> <C-w><
map <silent> <A-j> <C-W>-
map <silent> <A-k> <C-W>+
map <silent> <A-l> <C-w>>

With these mappings you can press Alt+ movement key to easily
resize. You can also say, e.g. 30<A-h> which increases by a larger
amount or simply keep <A-h> pressed for a few seconds.


Marco


Andy Wokula

unread,
Oct 26, 2012, 7:32:39 AM10/26/12
to vim...@googlegroups.com
You can have sub-modes if you want.

How to change window size with <C-W>+++-->>< :
https://groups.google.com/group/vim_use/browse_thread/thread/ac98f1e67faff909#a1fcfb4c997bdd75

--
Andy

Alexandre Provencio

unread,
Oct 26, 2012, 11:42:10 AM10/26/12
to vim...@googlegroups.com
I've found your mappings a neat solution Marco. I've made a little
adjustment for my setup though:

map <silent> <A-j> <C-W>+
map <silent> <A-k> <C-W>-

Thanks.

>
>
> Marco
>
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

Marco

unread,
Oct 26, 2012, 11:47:16 AM10/26/12
to vim...@googlegroups.com
2012-10-26 Alexandre Provencio:

> I've found your mappings a neat solution Marco. I've made a little
> adjustment for my setup though:
>
> map <silent> <A-j> <C-W>+
> map <silent> <A-k> <C-W>-

That's exactly the problem. If you have a split screen with two
window you want the separator to move *down* if <A-j> is pressed,
regardless if you are editing the upper or the lower buffer at the
moment.

If anyone on this list has a solution to this, please don't hesitate
sharing.


Marco


Ben Fritz

unread,
Oct 26, 2012, 11:50:30 AM10/26/12
to vim...@googlegroups.com, net...@lavabit.com
On Friday, October 26, 2012 10:47:42 AM UTC-5, Marco wrote:
>
> If you have a split screen with two
> window you want the separator to move *down* if <A-j> is pressed,
> regardless if you are editing the upper or the lower buffer at the
> moment.
>

What if you have 3 windows? Which separator should be acted on then?

Jimmy Wu

unread,
Oct 26, 2012, 12:05:00 PM10/26/12
to vim...@googlegroups.com
On Fri, Oct 26, 2012 at 11:50 AM, Ben Fritz <fritzo...@gmail.com> wrote:
> What if you have 3 windows? Which separator should be acted on then?

With 3 pane splits in tmux version 1.6, it appears the behavior is to
always move the bottom/right separator of the currently active pane,
except for the bottom/right-most pane which uses the top/left
separator.

(Note: tmux pane ~ vim window; tmux window ~ vim tab page)

Ben Fritz

unread,
Oct 26, 2012, 12:35:24 PM10/26/12
to vim...@googlegroups.com
So perhaps something like the following (untested) will do what you want:

func! MyResize()
let curwindow = winnr()

" if bottommost window, resize window just above, otherwise current window
wincmd j
if winnr() == curwindow
wincmd k
else
wincmd p
endif
resize +1

" restore current window
exec curwindow.'wincmd w'
endfun
nnoremap <A-j> :call MyResize()<CR>

You'd need to do a new function for each resize direction of course.

Ben Fritz

unread,
Oct 26, 2012, 12:38:01 PM10/26/12
to vim...@googlegroups.com
On Friday, October 26, 2012 11:35:24 AM UTC-5, Ben Fritz wrote:
>
> wincmd j
> if winnr() == curwindow
> wincmd k
> else
> wincmd p
> endif
>

Probably you should put a silent! in front of each of those wincmd lines to prevent Vim complaining when the desired movement is not possible.

lith

unread,
Oct 27, 2012, 7:20:22 AM10/27/12
to vim...@googlegroups.com, v...@vim.org, mail...@steelskies.com
> Other niceties from tmux are that you can press <C-b>jjjjj to carry on
> resizing, whereas in vim you'd have to use

You can use plugins like tinymode or tinykeymap (and some others) to create such maps.

Regards

Christian Brabandt

unread,
Oct 29, 2012, 8:00:00 AM10/29/12
to vim...@googlegroups.com
But tinykeymap doesn't work out of the box.
Just installed it from the vim.org site:

Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 9:
E121: Undefined variable: g:tinykeymap#mapleader
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 9:
E15: Invalid expression: g:tinykeymap#mapleader ."b" "{{{2
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 9:
E121: Undefined variable: g:tinykeymap#mapleader
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 9:
E15: Invalid expression: g:tinykeymap#mapleader ."b" "{{{2
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 16:
E121: Undefined variable: g:tinykeymap#map#buffers#map
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 16:
E116: Invalid arguments for function tinykeymap#EnterMap
Error detected while processing function tinykeymap#Map..<SNR>68_GetDict:
line 8:
E605: Exception not caught: tinykeymaps: Unknown map: buffers
Error detected while processing
U:\DE914854\vim\vimfiles\autoload\tinykeymap\map\buffers.vim:
line 16:
E121: Undefined variable: g:tinykeymap#map#buffers#map
Error detected while processing function tinykeymap#Load:
line 12:
E170: Missing :endfor

regards,
Christian

lith

unread,
Nov 9, 2012, 5:45:44 AM11/9/12
to vim...@googlegroups.com, cbl...@256bit.org
> But tinykeymap doesn't work out of the box.
> Just installed it from the vim.org site

Thanks for the error report. The script relied on mapleader to be set. It should work now.

Regards.

Reply all
Reply to author
Forward
0 new messages