103

I am working on split (using ^w+v, ^w+s) buffers, but sometimes I would like to widen a current split or change its height. How can I achieve that?

150

There are several window commands that allow you to do this:

  • Ctrl+W +/-: increase/decrease height (ex. 20<C-w>+)
  • Ctrl+W >/<: increase/decrease width (ex. 30<C-w><)
  • Ctrl+W _: set height (ex. 50<C-w>_)
  • Ctrl+W |: set width (ex. 50<C-w>|)
  • Ctrl+W =: equalize width and height of all windows

See also: :help CTRL-W

  • 18
    Might also be worth noting that the first two options can take a count to resize by more than one line/column at a time. – Rich Feb 6 '15 at 15:17
  • 4
    Might also be worth noting that the 3rd and 4th options can take no count to resize to the maximum height/width. – Michael Dec 2 '16 at 15:27
  • 2
    On my system, it's :help CTRL-W and not :help CTRL_W – Alexej Magura Apr 19 '17 at 19:27
  • on windows, Cygwin, vim : when you vimdiff -o bigfile1.bash bigfile2.bash : ctrl-w = : opens a MiniBufExplorer 3rd window on top (and the 3 windows are now equal in size), and closing that one makes the first .bash file's window 2 timse bigger than the 2nd .bash file window. Same operation with 2 .vim files gives same results. :( Same with vim -o – Olivier Dulac Oct 25 '17 at 17:03
  • Asking for shortcut for the first two options vi.stackexchange.com/questions/16786/… – KcFnMi Jul 18 '18 at 11:43
42

You can also use the resize commands:

  • :resize [+-]N - resize a horizontal split, increasing or decreasing height by N characters.
  • :vertical resize [+-]N - resize a vertical split, increasing or decreasing height by N characters.
  • :resize N - resize a horizontal split, setting height to N characters.
  • :vertical resize N - resize a vertical split, setting width to N characters.

These are equivalent to the Ctrlw commands. See :help window-resize.

27

This is one of the few reasons I like to use vim's mouse mode.

If you use the GUI version, or your terminal supports sending drag events (such as xterm or rxvt-unicode) you can click on the split line and drag to resize the window exactly where you want, without a lot of guess work using the ctrl-w plus,minus,less,greater combinations.

In terminal versions, you have to set mouse mode properly for this to work

:set mouse=n

(I use 'n', but 'a' also works)

and you have to set the tty mouse type

:set ttymouse=xterm2

A lot of people say that a lot of time is wasted using the mouse (mostly due to the time it takes to move your hand from the keyboard to the mouse and back), but I find that, in this case, the time saved by having immediate feedback while adjusting window sized and the quickness of re-resizing (keep movving the mouse instead of typing another key sequence) outweighs the delay of moingmy hand.

  • 4
    I couldn't agree more, I found in Gnome-terminal :set mouse=n is enough, but to enable when inside tmux :set ttymouse=xterm2 is needed. – the_velour_fog Nov 26 '15 at 3:17
  • 1
    Absolutely true, I love keyboard, but this kind of things are better with mouse. – calbertts Jun 26 '17 at 15:28
  • Wow, thanks for bringing this to my attention! – Charlie Gorichanaz Jul 30 '18 at 19:55
  • Totally agree with "but I find that, in this case, the time saved by having immediate feedback while adjusting window sized and the quickness of re-resizing (keep movving the mouse instead of typing another key sequence) outweighs the delay of moingmy hand.". – Nawaz Apr 9 at 2:46
4

Seems no one mentioned z{nr}<CR>.

If you :h ^w_, then will see z{nr}<CR> just below it, which have same effect as CTRL-W_.

If you do not need z= for spell check, and added below to .vimrc,

" vertical resize, z0<CR> minimize, z= equalize, z99<CR> maximize.
nnoremap z= <C-w>=

Then for change window height:

  • z0<CR> to minimize height of current window
  • z99<CR> to maxmize height of current window
  • z= to make them all equal
  • 1
    this use of z is a little unintuitive. I think we should stick to C-W mappings. It's nice to know what's out there though. – klaus May 21 '18 at 3:32
3

Resize splits more quickly: http://vim.wikia.com/wiki/Resize_splits_more_quickly

You can use the :resize command or its shortcut :res to change the height of the window. To change the height to 60 rows, use: :resize 60

You can also change the height in increments. To change the height by increments of 5, use: :res +5 :res -5

You can use :vertical resize to change the width of the current window. To change the width to 80 columns, use: :vertical resize 80

You can also change the width in increments. To change the width by increments of 5, use: :vertical resize +5 :vertical resize -5

  • This is very unlikely to be Resize splits more quickly, unless these commands are bound to keybindings, which has been done out of the box – klaus May 21 '18 at 3:34
  • Don't entirely agree Enan's statement. I like this answer imho – craft Dec 23 '18 at 14:53
0

For some reason (likely a plugin) the standard C-w > (etc.) did not work in my ~/.vimrc.

These .vimrc additions worked (Ctrl-Shift-Left ... where Left | Right = left and right arrow keys, respectively.

" noremap <silent> <C-S-Left> :vertical resize +5<CR>
" noremap <silent> <C-S-Right> :vertical resize -5<CR>
noremap <silent> <C-S-Left> :vertical resize +1<CR>
noremap <silent> <C-S-Right> :vertical resize -1<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.