Question

Why do my vim plugins not open at startup unless I open vim like this:

❯ cd path/to/directory
path/to/directory❯ vim

Why can't I open it like this?

❯ vim path/to/directory
Was it helpful?

Solution

Your autocmd that automatically opens NERDTree checks for the number of arguments (argc()), and only opens NERDTree if none are specified:

" Only open nerdtree if no file was specified on startup
function! StartUpNerdtree()
    if 0 == argc()
        NERDTree
    end
endfunction

autocmd VimEnter * call StartUpNerdtree()

That makes sense in a way: If you pass a file(s) when opening Vim, you probably don't need the directory browser. Now, to tweak this function to what you want, the conditional needs to be extended to check for a single directory argument: Replace

    if 0 == argc()

with

    if 0 == argc() || 1 == argc() && isdirectory(argv(0))

Note: What exactly happens with this change depends on your (NERDTree) configuration; you didn't include this in the question nor did you specify the desired behavior. I hope you get the idea and can tweak this according to your expectations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top