Floegipoky
Floegipoky

Reputation: 3273

Open NERDTree when vim is opened without args, but not with -

I would like NERDTree to open on startup when I start vim without any arguments, but I don't want it to open when I use foo | vim -

I have autocmd VimEnter * if !argc() | NERDTree | endif in my vimrc already, but of course this still opens it with vim -

Upvotes: 1

Views: 600

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172520

You can use the StdinReadPre event to set a flag to detect this:

autocmd StdinReadPre * let g:isReadingFromStdin = 1
autocmd VimEnter * if !argc() && !exists('g:isReadingFromStdin') | NERDTree | endif

Upvotes: 3

Related Questions