I set up my .vimrc so that NERDTree automatically shows up on the left when opening vim for editing a file (autocmd VimEnter * NERDTree). This means, that NERDTree is the active buffer instead, and I have to press <C-w>w every time to focus on the file I want to edit.

How can I achieve this automatically?

  • How did you configure NERDTree to automatically show up? You probably want to change this customization so it would be useful to show it in the question. (Also, clearly not an answer but mandatory link on questions about Nerdtree and why not to use it: oil and vinegar)
    – statox
    Apr 20 '18 at 8:04
  • autocmd VimEnter * NERDTree that's all. Apr 20 '18 at 8:12

You can change your autocommand to execute <c-w>w after executing NERDTree. To do so you can use wincmd which is the equivalent of pressing <C-w> but with a command (see :h :wincmd)

autocmd! VimEnter * NERDTree | wincmd w
  • 1
    Works for me without backslash as well: au VimEnter * NERDTree | wincmd w Apr 3 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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