To deal with splits I use the submode-plugin which is actually pretty convenient: It allows you to create a new mode ("mode" like in normal mode, visual mode, insert mode, etc...) where you define new key bindings.
With that you don't have to use Ctrl+w anymore and as you are in a new mode all the keys are free to bind: no more problems like "Damn I can't find a key combination which as a signification and isn't mapped yet"
You can install the plugin with any regular plugin manager, and here are some of my configuration to give you some inspiration:
I created a new mode that I called WindowsMode
in which I manipulate my splits:
call submode#enter_with('WindowsMode', 'n', '', '<Leader>k', ':echo "windows mode"<CR>')
call submode#leave_with('WindowsMode', 'n', '', '<Leader>')
These lines means that I enter in the mode with Leaderk and I exit the mode with Leader: After I hit Leaderk all the keys I hit will:
- Do nothing if I didn't defined a mapping for them in this mode
- Do what I decided to map them in this mode (see the rest of the answer)
- Go back to normal mode if I hit Leader
Once I'm in WindowsMode
these lines make hjkl navigate through the splits like Ctrl+whjkl
" Change of windows with hjkl
call submode#map('WindowsMode', 'n', '', 'j', '<C-w>j')
call submode#map('WindowsMode', 'n', '', 'k', '<C-w>k')
call submode#map('WindowsMode', 'n', '', 'h', '<C-w>h')
call submode#map('WindowsMode', 'n', '', 'l', '<C-w>l')
I used these lines to split the windows with / and !:
" split windows with / and !
call submode#map('WindowsMode', 'n', '', '/', '<C-w>s')
call submode#map('WindowsMode', 'n', '', '!', '<C-w>v')
And q close a split:
call submode#map('WindowsMode', 'n', '', 'q', '<C-w>c')
Move the splits with Ctrlhjkl:
call submode#map('WindowsMode', 'n', '', '<C-j>', '<C-w>J')
call submode#map('WindowsMode', 'n', '', '<C-k>', '<C-w>K')
call submode#map('WindowsMode', 'n', '', '<C-h>', '<C-w>H')
call submode#map('WindowsMode', 'n', '', '<C-l>', '<C-w>L')
Vim-submode allows to do a lot of powerful things, see the doc for more details.
EDIT Another approach of the Window submode is described here. I think the method used by the author is even closer to answer the question: Here is used to create a new mode but all the <c-w>something
mappings are available with the same keys in the submode:
" Go through every letter
for key in ['a','b','c','d','e','f','g','h','i','j','k','l','m',
\ 'n','o','p','q','r','s','t','u','v','w','x','y','z']
" maps lowercase, uppercase and <C-key>
call submode#map('window', 'n', '', key, '<C-w>' . key)
call submode#map('window', 'n', '', toupper(key), '<C-w>' . toupper(key))
call submode#map('window', 'n', '', '<C-' . key . '>', '<C-w>' . '<C-'.key . '>')
endfor
" Go through symbols. Sadly, '|', not supported in submode plugin.
for key in ['=','_','+','-','<','>']
call submode#map('window', 'n', '', key, '<C-w>' . key)
endfor
This way all the mappings <c-w>lowerCaseKey
, <c-w>upperCaseKey
, <c-w><c-Key>
and the mappings <c-w>=_+-<>
are all accessible in the window mode without the prefix <c-w>
wincmd
For example you can map::nmap wj :wincmd j<cr>
it's acts same asCTRL-W j
(move to window below).:help wincmd
CTRL-W j
works with counters (go to n-th window below from current) my solution does not.<C-W>
is too useful a shortcut (not only in many places in Vim, but also in bash) to forfeit. I'd be curious what other key bindings are consumed by the terminal --<C-T>
? At the very least, I'd look into whether these are configurable in the terminal.