How to increase the vertical split window size in Vim

VimWindowViewport

Vim Problem Overview


:vsplit (short form: :vs) split the Vim viewport vertically. :30vs splits the viewport, making the new window 30 characters wide. Once this 30 char window is created, how would one change it's size to 31 or 29?

With horizontal windows Ctrl-W + increases the number of lines by one. What is the equivalent command to increase the columns by one?

Vim Solutions


Solution 1 - Vim

CTRL-W >

and

CTRL-W <

to make the window wider or narrower.

Solution 2 - Vim

And Ctr-W =

will make them equal

Solution 3 - Vim

In case you need HORIZONTAL SPLIT resize as well:
The command is the same for all splits, just the parameter changes:

- + instead of < >

Examples:
Decrease horizontal size by 10 columns

:10winc -

Increase horizontal size by 30 columns

:30winc +

or within normal mode:

Horizontal splits

10 CTRL+w -

30 CTRL+w +

Vertical splits

10 CTRL+w < (decrease)

30 CTRL+w > (increase)

Solution 4 - Vim

Another tip from my side:

In order to set the window's width to let's say exactly 80 columns, use

80 CTRL+W |

In order to set it to maximum width, just omit the preceding number:

CTRL+W |

Solution 5 - Vim

I have these mapped in my .gvimrc to let me hit command-[arrow] to move the height and width of my current window around:

" resize current buffer by +/- 5 
nnoremap <D-left> :vertical resize -5<cr>
nnoremap <D-down> :resize +5<cr>
nnoremap <D-up> :resize -5<cr>
nnoremap <D-right> :vertical resize +5<cr>

For MacVim, you have to put them in your .gvimrc (and not your .vimrc) as they'll otherwise get overwritten by the system .gvimrc

Solution 6 - Vim

Along the same lines, I use the following in my .vimrc to let me move through the splits, automatically expanding the one I'm moving to to its full size and shrinking all the rest to their minimum height or width:

" Switch between window splits using big J or K and expand the split to its 
" full size. 
" 
" Move vertically in the window through the horizontal splits... 
map <C-J> <C-w>j<C-w>_ 
map <C-K> <C-w>k<C-w>_ 

" Move horizontally in the window through the vertical splits... 
map <C-H> <C-w>h<C-w>\| 
map <C-L> <C-w>l<C-w>\| 

Solution 7 - Vim

This is what I am using as of now:

nnoremap <silent> <Leader>= :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <silent> <Leader>0 :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
nnoremap <silent> <Leader>9 :exe "vertical resize " . (winwidth(0) * 2/3)<CR>

Solution 8 - Vim

I am using numbers to resize by mapping the following in .vimrc

nmap 7 :res +2<CR> " increase pane by 2 
nmap 8 :res -2<CR> " decrease pane by 2
nmap 9 :vertical res +2<CR> " vertical increase pane by 2
nmap 0 :vertical res -2<CR> " vertical decrease pane by 2

Solution 9 - Vim

For changing width use "vertical resize" and for changing height use "resize".

I have done following mapping in my .vimrc

  1. ALT will increase width of the selected split

  2. ALT will decrease width of the selected split

  3. ALT will increase height of the selected split

  4. ALT will decrease height of the selected split

My .vimrc code:

nmap <M-Right> :vertical resize +1<CR>
nmap <M-Left> :vertical resize -1<CR>
nmap <M-Down> :resize +1<CR>
nmap <M-Up> :resize -1<CR>

Vim Resize Splits more quickly

Solution 10 - Vim

I am using the below commands for this:

set lines=50     " For increasing the height to 50 lines (vertical)
set columns=200  " For increasing the width to 200 columns (horizontal)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmoliculeView Question on Stackoverflow
Solution 1 - VimHerbert SitzView Answer on Stackoverflow
Solution 2 - VimRusAlexView Answer on Stackoverflow
Solution 3 - VimfreeoView Answer on Stackoverflow
Solution 4 - VimPhilView Answer on Stackoverflow
Solution 5 - VimTed NaleidView Answer on Stackoverflow
Solution 6 - Vimthe Tin ManView Answer on Stackoverflow
Solution 7 - VimmeainView Answer on Stackoverflow
Solution 8 - VimGajendra JenaView Answer on Stackoverflow
Solution 9 - VimABNView Answer on Stackoverflow
Solution 10 - VimimbichieView Answer on Stackoverflow