Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim split window: Focus new window

Tags:

vim

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?

like image 334
Steven Lu Avatar asked May 16 '13 18:05

Steven Lu


People also ask

How do I navigate between split windows in Vim?

To move between splits first press Ctrl-w (I remember this by Control Window, I'm not sure what the official mnemonic is) Then press a directional key to move the cursor to the split you're interested in. Directional key could be the arrows or my preferred home row method.

How do I switch between panes in Vim?

Control + W followed by W to toggle between open windows and, Control + W followed by H / J / K / L to move to the left/bottom/top/right window accordingly, Control + W followed by Left / Down / Up / Right arrow to move to the left/bottom/top/right window accordingly.


1 Answers

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
like image 162
FDinoff Avatar answered Sep 24 '22 11:09

FDinoff