1

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?

2
  • 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, 2018 at 8:04
  • autocmd VimEnter * NERDTree that's all. Apr 20, 2018 at 8:12

1 Answer 1

9

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
  • 1
    Works for me without backslash as well: au VimEnter * NERDTree | wincmd w Apr 3, 2019 at 15:03

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.