I am slowly learning vim and its powerful capabilities. I have a question in regards to splitting windows (mainly horizontal splits). Is there a way to automatically resize the currently selected (focused) window? Let's say, for example, a setting so that the focused window will always take up 70% of the screen.
Using Ctrl-w (number) +/- every time is not really efficient, especially when I am jumping between a few files constantly.
Also it would be cool if there was a way to restrict it to only horizontally splitted windows.
The 'winheight'
setting determines the minimal number of lines for the current window. Some users set this to 999 for "Rolodex mode". The following sets this to 70%:
:let &winheight = &lines * 7 / 10
For anything fancier, you can hook into the WinEnter
event via an :autocmd
, and then set the window height to N via :Nwincmd _
. Stupid example:
:autocmd WinEnter * execute winnr() * 2 . 'wincmd _'
Sounds like you want golden-ratio : Resize windows automatically using the Golden Ratio.
Once I found out you could disable the "automatic" part of golden-ratio, I started using it myself with these settings:
" Don't resize automatically.
let g:golden_ratio_autocommand = 0
" Mnemonic: - is next to =, but instead of resizing equally, all windows are
" resized to focus on the current.
nmap <C-w>- <Plug>(golden_ratio_resize)
" Fill screen with current window.
nnoremap <C-w>+ <C-w><Bar><C-w>_
I use these mapping for split screens:
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap c<C-j> :bel sp new<cr>
nnoremap c<C-k> :abo sp new<cr>
nnoremap c<C-h> :lefta vsp new<cr>
nnoremap c<C-l> :rightb vsp new<cr>
nnoremap g<C-j> <C-w>j<C-w>_
nnoremap g<C-k> <C-w>k<C-w>_
nnoremap g<C-h> <C-w>h<C-w>_
nnoremap g<C-l> <C-w>l<C-w>_
nnoremap d<C-j> <C-w>j<C-w>c
nnoremap d<C-k> <C-w>k<C-w>c
nnoremap d<C-h> <C-w>h<C-w>c
nnoremap d<C-l> <C-w>l<C-w>c
This way if you want to jump between splits you can use C-hjkl. If you want to "create" a split you can use cC-hjkl. If you want to maximize a split you can use gC-hjkl. And if you want to delete a split you can use dC-hjkl.
If you want specifically 70% instead of maximized that you could use
nnoremap g<C-j> <C-w>j:let &winheight = &lines * 7 / 10<cr>
for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With