Walking Around Your Windows
Vim can do an insane number of things with windows in Vim. I take a minimalist approach to windows in Vim and try to make it as simple for myself as possible. There are a number of factors that drive my configuration:
- I always use my left hand to hit the CTRL key. The main key that is used for windowing is
CTRL-W. - I prefer to have multiple key sequences to occur on opposing hands when possible.
CTRL-Wis two simultaneous keys on the same hand. - It’s all about reusing existing habits when I can. So
h,j,kandlare important to reuse. The existing Vim solution actually already does this.
Those points lead me to have the following mappings for window management:
" Move the cursor to the window left of the current one
noremap <silent> ,h :wincmd h<cr>
" Move the cursor to the window below the current one
noremap <silent> ,j :wincmd j<cr>
" Move the cursor to the window above the current one
noremap <silent> ,k :wincmd k<cr>
" Move the cursor to the window right of the current one
noremap <silent> ,l :wincmd l<cr>
" Close the window below this one
noremap <silent> ,cj :wincmd j<cr>:close<cr>
" Close the window above this one
noremap <silent> ,ck :wincmd k<cr>:close<cr>
" Close the window to the left of this one
noremap <silent> ,ch :wincmd h<cr>:close<cr>
" Close the window to the right of this one
noremap <silent> ,cl :wincmd l<cr>:close<cr>
" Close the current window
noremap <silent> ,cc :close<cr>
" Move the current window to the right of the main Vim window
noremap <silent> ,ml <C-W>L
" Move the current window to the top of the main Vim window
noremap <silent> ,mk <C-W>K
" Move the current window to the left of the main Vim window
noremap <silent> ,mh <C-W>H
" Move the current window to the bottom of the main Vim window
noremap <silent> ,mj <C-W>J
Nikos Aggelidis:
August 22nd, 2009 at 3:38 pm
for movements between windows, i use shift + h,j,k,l .
I also like to follow the rule:
“I prefer to have multiple key sequences to occur on opposing hands when possible. “
Mike B:
October 12th, 2009 at 7:00 am
It looks like the ‘s got stripped from the mappings.
Mike B:
October 12th, 2009 at 7:01 am
Let’s try that again:
It looks like the (less than sign)CR(greater than sign)’s got stripped from the mappings.
Derek Wyatt:
October 12th, 2009 at 12:20 pm
You’re right! Bloody wordpress :) Should be good now… thanks to the Vim blogit plugin… beauty stuff :)
Mitko:
November 25th, 2009 at 2:55 am
You shouldn’t use , as a map leader. It is an important feature of vim. :h,
Derek Wyatt:
November 25th, 2009 at 3:29 am
That’s why I have ‘[vn]noremap <c-e> ,’
I’ll keep using ‘,’ as a mapleader, thanks :)
Mitko:
November 27th, 2009 at 3:45 am
Sorry to insist but c-e is important for scrolling in normal mode :)
Derek Wyatt:
November 27th, 2009 at 3:57 am
Obviously not to me. :) Fortunately Vim’s configuration allows us to get rid of stuff that we don’t really find all that useful.
The main issue is that ‘\’ sucks as a map leader… it’s placed differently on almost every keyboard out there and it’s right next to the enter key a lot of the time. Making a mistake once in a while is OK but when you hit the key a hundred times an hour, making mistake after mistake after mistake is a real pain in the butt. The ‘,’ key is easily accessible and universally placed – using it as a map leader is far preferable to me, and <c-e> is mostly useless considering there are *so many* other ways to scroll around.
Mitko:
November 27th, 2009 at 4:16 am
Fair enough,
I am using c-e quite a lot and find it very usefull indeed and \ is just besides my left shift key so I do use it as a map leader but your arguments make sense… for you :)