Reputation: 43547
I have mapped for convenience:
" this is a ctrl + backslash binding to vsplit
nmap <C-\> :vsplit<CR>
" this is a ctrl + hyphen binding to hsplit
nmap <C-_> :split<CR>
This is good but needs one more final touch to behave the way I want which is that it should focus the newly created window so I can immediately open up whatever file I want in it using traditional :e
or CtrlP plugin. As it is now, doing that is going to navigate from the original window which is slightly disorienting.
How can I get :split
and :vsplit
to auto-focus the newly created vim window?
Upvotes: 9
Views: 6859
Reputation: 31459
When I open the new split my cursor is automatically focused in the new window by default. What you probably don't realise is that the new vertical split is put on the left and the new horizontal split is put on the top.
To open new splits on the right or on the bottom of the screen add the following to your vimrc.
set splitbelow
set splitright
Upvotes: 29
Reputation: 10270
I'm not sure if it's 100% flexible and works in every situation, but you could combine it with a move cursor to another window command, such as ctrlw+w.
nnoremap <C-\> <C-w>v<C-w>w
<C-w>v
- like :vsplit
<C-w>w
- move cursor to window below/right of the current oneUpvotes: 3