Question

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.

Was it helpful?

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().

OTHER TIPS

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

The greatest part of this code was taken from this question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top