当 vim 不带参数打开时打开 NERDTree,但不带 -

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

我希望 NERDTree 在我不带任何参数启动 vim 时在启动时打开,但我不希望它在我使用 foo | vim -

时打开

我的 vimrc 中已经有 autocmd VimEnter * if !argc() | NERDTree | endif,当然这仍然会用 vim -

打开它

您可以使用 StdinReadPre 事件设置一个标志来检测:

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