Search code examples
vimnerdtree

vim: open NERDTree and move the cursor to the file editing area


I tried following the instruction in FAQ section on NERDTree github site:

"Q. How can I open a NERDTree automatically when vim starts up?"

"A. Stick this in your vimrc: autocmd vimenter * NERDTree"

It works but when I open a file the cursor stay in the NEARDTree explorer area but not in the edit area, I have to press Ctrl+w+l to move it back, what should I write in my .vimrc file to automate setting the cursor in the edit area?


Solution

  • Just add this second command right after:

    autocmd VimEnter * NERDTree
    autocmd VimEnter * wincmd p
    

    Or if you want a one-liner

    autocmd VimEnter * NERDTree | wincmd p