RaZ
RaZ

Reputation: 384

VIM: Open netrw on startup or open files provided

I've added a little quality-of-life improvement to the .vimrc which invokes netrw @ startup, namely:

augroup ProjectDrawer
  autocmd!
  autocmd VimEnter * :Explore!
augroup END

Works like a charm, however this interferes with invoking vim to edit a particular file vim file_foo (I end up with netrw not with file_foo).

How can I modify my .vimrc to e.g. invoke ProjectDrawer when there were no arguments to the vim on invocation (vim), otherwise open provided files (vim file_foo)?

Upvotes: 6

Views: 1708

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172500

You can add a conditional that checks argc(), which gives the number of arguments passed to Vim (the arguments itself are returned by argv({nr})):

augroup ProjectDrawer
    autocmd!
    autocmd VimEnter * if argc() == 0 | Explore! | endif
augroup END

Upvotes: 6

Related Questions