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?
6 Answers
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
- 13Might also be worth noting that the 3rd and 4th options can take no count to resize to the maximum height/width.Michael come lately– Michael come lately2016-12-02 15:27:01 +00:00Commented Dec 2, 2016 at 15:27
- 1on 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 withvim -oOlivier Dulac– Olivier Dulac2017-10-25 17:03:23 +00:00Commented Oct 25, 2017 at 17:03 - Asking for shortcut for the first two options vi.stackexchange.com/questions/16786/…KcFnMi– KcFnMi2018-07-18 11:43:39 +00:00Commented Jul 18, 2018 at 11:43
- 1@job_start I don't know what to tell you. I wrote a script using it in 2016, and it's still in use today with no complaints.
execute "norm! \<c-W>_"Michael come lately– Michael come lately2021-04-03 19:42:35 +00:00Commented Apr 3, 2021 at 19:42 - 1The documentation says "Set current window height to N (default: highest possible)."Michael come lately– Michael come lately2021-04-05 13:03:43 +00:00Commented Apr 5, 2021 at 13:03
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.
- Similar to: vim.wikia.com/wiki/Resize_splits_more_quicklyFilBot3– FilBot32018-11-27 15:43:50 +00:00Commented Nov 27, 2018 at 15:43
- 2I am so happy I finally found the easiest way to do this is resize command. Control commands are a menace, I keep playing ping pong without resizing any frame with it.. thank you @murunitinr708– nitinr7082020-03-10 14:55:21 +00:00Commented Mar 10, 2020 at 14:55
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 the window sizes and the quickness of re-resizing (keep moving the mouse instead of typing another key sequence) outweighs the delay of moving my hand.
- 12I couldn't agree more, I found in Gnome-terminal
:set mouse=nis enough, but to enable when inside tmux:set ttymouse=xterm2is needed.the_velour_fog– the_velour_fog2015-11-26 03:17:11 +00:00Commented Nov 26, 2015 at 3:17 - 2Absolutely true, I love keyboard, but this kind of things are better with mouse.calbertts– calbertts2017-06-26 15:28:44 +00:00Commented Jun 26, 2017 at 15:28
- 3Totally 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.".Sarfaraz Nawaz– Sarfaraz Nawaz2019-04-09 02:46:46 +00:00Commented Apr 9, 2019 at 2:46
- 1This is decidedly the best answer for which I could have hoped!! Brilliant. I did this and nothing changed visually for me, but I went ahead and tried to "grab" the borders (even though my cursor didn't change, of course) and IT WORKED! I am a huge advocate of No Mouse (tm), however, this is the reason to use this. amazing. 🙏🏽Metagrapher– Metagrapher2025-02-19 00:26:47 +00:00Commented Feb 19 at 0:26
- This is totally going in my .vimrc THANK YOU!Metagrapher– Metagrapher2025-02-19 00:27:52 +00:00Commented Feb 19 at 0:27
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
- 5this use of
zis a little unintuitive. I think we should stick toC-Wmappings. It's nice to know what's out there though.3N4N– 3N4N2018-05-21 03:32:28 +00:00Commented May 21, 2018 at 3:32
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 - 2This is very unlikely to be
Resize splits more quickly, unless these commands are bound to keybindings, which has been done out of the box3N4N– 3N4N2018-05-21 03:34:02 +00:00Commented May 21, 2018 at 3:34 - Don't entirely agree Enan's statement. I like this answer imhocraft– craft2018-12-23 14:53:44 +00:00Commented Dec 23, 2018 at 14:53
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> - I just tried this and got an error message when trying C-S-Left: "E16: Invalid range".Magnus– Magnus2020-06-15 14:11:44 +00:00Commented Jun 15, 2020 at 14:11
- @Magnus : just looked at my
~/.vimrc: as above. Tested on:vsin Vim 8.2 (Linux system): works. Perhaps you have an error in your lines (or some other issue)? imgur.com/gallery/h7lGYhKVictoria Stuart– Victoria Stuart2020-06-15 15:14:40 +00:00Commented Jun 15, 2020 at 15:14