Call Vim auto command when opening "nothing"

I want vim to open: Explorer when the file does not open and is not created. For instance. when i call vim without any parameters.

calling vim newfile.txt should still behave in the usual way.

How can I do it? It seems I can not find the correct autocmd for it.

+4
source share
2 answers

If you want to do this just for calling vim, the best way is to use argc() :

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

argc() returns the number of file names specified on the command line when calling vim, unless something else is changed, more information is in :h argc() .

+5
source

Found the answer myself:

 "open to Explorer when no file is opened function! TabIsEmpty() " Remember which window we're in at the moment let initial_win_num = winnr() let win_count = 0 " Add the length of the file name on to count: " this will be 0 if there is no file name windo let win_count += len(expand('%')) " Go back to the initial window exe initial_win_num . "wincmd w" " Check count if win_count == 0 " Tab page is empty return 1 else return 0 endif endfunction " Test it like this: " echo TabIsEmpty() function! OpenExplorer() if (TabIsEmpty()) :Explore end endfunction 

Most of this code was taken from this question .

+2
source

All Articles