5

I have the following line in my .vimrc to open NERDTree on startup:

NERDTreeToggle

Now, if I start vim, I have NERDTree on the left and the file I opened on the right.

The left window is focused on startup. How can I put the focus on the right window on startup?

3
  • 1
    I don't have NERDTree installed, so I can't test it, but does au VimEnter * wincmd l work?
    – DJMcMayhem
    Nov 21, 2016 at 18:28
  • Do you really have that command in your .vimrc? That shouldn't yet be available when Vim starts up. Nov 21, 2016 at 18:47
  • I load "NERDTree" with "vim-plug" (a package manager for vim). This line in my .vimrc loads NT immediately: Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }, so I can use NERDTreeToggl in .vimrc
    – Rotareti
    Nov 21, 2016 at 18:58

1 Answer 1

9

You can do this with a simple autocommand:

au VimEnter * wincmd l

This tells vim anytime you open a new vim window (VimEnter) on any file type * to run the ex command :wincmd l. wincmd l is effectively the same thing as pressing <C-w>l in normal mode, which moves you one split to the right. From :h ctrl_w-l

CTRL-W CTRL-L                   *CTRL-W_CTRL-L* *CTRL-W_l*
CTRL-W l    Move cursor to Nth window right of current one.  Uses the
        cursor position to select between alternatives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.