I open nerdtree
by doing:
$ mvim .
If I then do:
:NERDTree
I get two vertical panes showing a tree view. In the left pane, if I navigate to a file and hit o
, the file opens in the right pane. On the other hand, if I navigate to a file in the right pane and hit o
, the file opens in the right pane. That is the setup I want, but I don't want to have to type :NERDTree
to get there.
I am trying to setup nerdtree so that when I do:
$ mvim .
two vertical panes open up automatically. I found this vimscript:
"Nerdtree--open two windows on startup
autocmd vimenter * call s:CheckToSplitTwoTrees()
function! s:CheckToSplitTwoTrees()
if argc() != 1 || !isdirectory(argv(0))
return
endif
vsplit
"there should really be a better way to do this... e.g. :NERDTreeSecondary
call nerdtree#checkForBrowse(argv(0))
endfunction
which does what I want, however o
in the left pane opens files in the left pane--not the right pane. What controls what pane o
opens a file in?
If you simply want - on startup - to execute :NERDTree
on the first argument if it is a directory, your function is ok, but just execute the desired command.
"Nerdtree--open two windows on startup
autocmd vimenter * call s:CheckToSplitTwoTrees()
function! s:CheckToSplitTwoTrees()
if argc() != 1 || !isdirectory(argv(0))
return
endif
exe 'NERDTree '.argv(0)
endfunction
When NERDTree plugin is installed, opening vim with a directory automatically shows a NerdTree browser (primary, where o
opens the file replacing the browser) instead of the regular netrw browser. So, executing ':NERDTree '.argv(0)
opens up the usual (secondary) NERDTree where o
opens on the right pane.
Check also this related question.