Skip to content

Instantly share code, notes, and snippets.

@scrooloose
Created July 4, 2014 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scrooloose/50ec0b131b2861e58af3 to your computer and use it in GitHub Desktop.
Save scrooloose/50ec0b131b2861e58af3 to your computer and use it in GitHub Desktop.
"put this in your vimrc
"note: I'll probably add :NERDTreeSecondary after work tonight
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
@7stud
Copy link

7stud commented Jul 7, 2019

Edit: Something doesn't work correctly. I'm used to navigating to a file in the tree view in the left pane and hitting o to make the file open in the right pane. With this vimscript, when I hit o in the left pane, the file opens in the left pane.


Nice! I'm sick of typing:

$ mvim .

then

:NERDTree

How about having the cursor start in the right hand window? My setup is tree view on left, and file on right; so if the cursor starts in the right hand window, I can navigate to a file and hit "o"--and not have to do any window switching.

Ha! Here it is: after the line vsplit add wincmd l:

autocmd vimenter * call s:CheckToSplitTwoTrees()
function! s:CheckToSplitTwoTrees()
    if argc() != 1 || !isdirectory(argv(0))
        return
    endif

    vsplit
    wincmd l

    "there should really be a better way to do this... e.g. :NERDTreeSecondary
    call nerdtree#checkForBrowse(argv(0))
endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment