Search code examples
vimautocmd

Vim autocommand trigger on opening "nothing"


I want vim to open up the :Explorer when no file is opened or created. Eg. when I call vim without any options.

calling vim newfile.txt should still behave the normal way though.

How would I go about doing this? I can't seem to find the correct autocmd for it.


Solution

  • If you want to do this for vim invocation only, the best way is to use argc():

    autocmd VimEnter * :if argc() is 0 | Explore | endif
    

    argc() function returns a number of filenames specified on command-line when vim was invoked unless something modified arguments list, more information at :h argc().