Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Minimizing" vertical VIM window splits

Tags:

vim

I use horizontal and vertical window splits in religiously in VIM and up until recently, I enjoyed the comfort of two commands to effectively hide (or minimize) my horizontal splits. I set them up adding the following lines to my .vimrc file:

set winminheight=0
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_

Hitting Control-j or Control-k navigates through horizontal splits by going up or down. What I'd like to accomplish is the same thing for vertical splits by showing or hiding the left or right split using Control-Shift-h and Control-Shift-l; h moving to the left, l moving to the right. I have tried the following with little to no success:

set winminwidth=0
map <S-C-L> 500<C-W>h<C-W>_
map <S-C-H> 500<C-W>l<C-W>_

The action would be similar to utilizing Control-w-< and Control-w->, only moving the vertical split completely to the left or write, not just one line at a time.

Any ideas on how to accomplish this? Thanks.

like image 564
chuckg Avatar asked Aug 11 '09 18:08

chuckg


3 Answers

First up, you won't be able to use <S-C- (shift + control) in your code (see below). But you can use the 'mapleader' as your "shift" and then use the <C-h> and <C-l> like you want to. Like this:

set winminwidth=0
nmap <Leader><C-h> <C-W>h500<C-W>>             
nmap <Leader><C-l> <C-W>l500<C-W>>               

The common leader keys in vim are comma and back-slash:

:let mapleader = ","

But you'll find that this gets annoying to require 3 keystrokes for this, so you might as well just drop the control key stroke. This way (if your leader is comma) you can just press ",h" and ",l" to go to the splits to your left and right:

set winminwidth=0
nmap <Leader>h <C-W>h500<C-W>>             
nmap <Leader>l <C-W>l500<C-W>>       

" (FTW) :D

...

A guy named Tony Chapman answers why you can't use control + shift:

Vim maps its Ctrl+printable_key combinations according to ASCII. This means that "Ctrl+lowercase letter" is the same as the corresponding "Ctrl+uppercase letter" and that Ctrl+<key> (where <key> is a printable key) is only defined when <key> is in the range 0x40-0x5F, a lowercase letter, or a question mark. It also means that Ctrl-[ is the same as Esc, Ctrl-M is the same as Enter, Ctrl-I is the same as Tab.

So yes, Ctrl-s and Ctrl-S (i.e. Ctrl-s and Ctrl-Shift-s) are the same to Vim. This is by design and is not going to change.

like image 96
ashleydev Avatar answered Sep 18 '22 13:09

ashleydev


Try

set winminwidth=0
map <S-C-L> <C-W>h<C-W>|
map <S-C-H> <C-W>l<C-W>|

This doesn't move a window completely to the left or right (that's <C-W>H and <C-W>L), it just moves the cursor to the left (or right) window and maximizes that window horizontally.

See :help CTRL-W_bar for more.

like image 33
rampion Avatar answered Sep 21 '22 13:09

rampion


Crl-w 1 |

will minimize current window in Vim.

like image 24
Александр Тарасов Avatar answered Sep 21 '22 13:09

Александр Тарасов