Last Updated: February 25, 2016
·
5.257K
· lwheng

vim: Adding shortcuts (nmap) in your .vimrc for switching between and resizing splits

This is related to my previous tip: https://coderwall.com/p/44lupw
Thanks to Sergey Shulym for the suggestion.

So say you now have so many splits in your vim, how do you jump between each split window? Here's the command:

Ctrl + w, w

That's a bit troublesome right? So let us add a shortcut to your .vimrc using nmap

nmap <Tab> <C-w>w

What did we just do? We just mapped the Tab key on your keyboard to the command to switch split windows (C here means Ctrl). You can set it to be another key, but Tab is my preference.

You can now type one key to quickly switch between split windows. Hurray!

Just one more thing.

So you have many split windows from opening so many files at one go, the splits become too small to see anything and you need to resize the one you are working on. The command is:

:res+5
:vertical res-5

Go ahead, try it. + to increase, - to decrease. You get the point. You get that this is also too troublesome. Here's my shortcut in my .vimrc:

nmap 7 :vertical res-5<CR>
nmap 8 :vertical res+5<CR>
nmap 9 :res-5<CR>
nmap 0 :res+5<CR>

Again, I preferred to have these 4 digits for my shortcuts. So go ahead and try them now. You now look and feel more pro in vim. =D

(This tip is entirely for my previously shared tip and not to compete who has the best .vimrc)

2 Responses
Add your response

Do note that if you're using Ctrl+O to jump back to a previously opeedn file, assigning TAB to something disables Ctrl+I (which is jumping forwards), because TAB and Ctrl+I are the same.

I use Ctrl+O and Ctrl+I a lot in my flow, so I'll have to think of some other shortcut binding. :/

over 1 year ago ·

Love using the Tab to cycle splits. Use it everyday. As for previous file: I use this
noremap <leader><leader> <c-^>

My <leader> key is mapped to comma. So hitting comma twice brings me back to the previous file.

over 1 year ago ·