Troskyvs
Troskyvs

Reputation: 8077

vimrc: how to auto change window focus when vim is loaded

I've let tagbar and NERDtree autoload when vim is opening any file. The window layout from left to right is:

NERDTree----My source code----TagBar

The problem is, each time vim is up, the NERDtree on the left gets the focus(keyboard). I wish to make the middle window(My source code) having the focus, so I can start coding immediately. Or else I have to C-w l to switch windows each time.

How to set this in ~/.vimrc?

Thanks a lot.

Upvotes: 0

Views: 1449

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172688

The plugins probably use :autocmd VimEnter to open their sidebars. You can define a similar autocmd, but it has to run after the plugins'.

Put the following into ~/.vim/after/plugin/middleWindow.vim:

autocmd VimEnter * 2wincmd w

This goes to the second available window.

Upvotes: 1

XPlatformer
XPlatformer

Reputation: 1228

It's a bit tricky, because I don't know when in your start-up sequence, all three buffers are loaded. If you use Vim8, you can do the wincmd on a timer. This works for me:

call timer_start(100, { -> execute( "wincmd l") })

Upvotes: 1

Related Questions