Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

nerdtree

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?

like image 790
Bamqf Avatar asked Jul 17 '14 16:07

Bamqf


2 Answers

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 
like image 197
dave Avatar answered Sep 27 '22 16:09

dave


If you want to keep the default behavior if no file is specified (i.e. leave the NERDTree explorer only if there is a file to edit) you can use this setting:

autocmd VimEnter * if argc() == 1 | NERDTree | wincmd p | endif

like image 34
garrettmaring Avatar answered Sep 27 '22 16:09

garrettmaring