Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .vimrc, how to test whether any filename arguments are given to Vim at invocation?

Tags:

vim

The answer to the question Using vim Sessions Only With GUI? suggests using

au VimLeave * mksession! ~/.gvimsession
au VimEnter * source ~/.gvimsession

My problem is when I start Vim, say, by issuing $ gvim test.html, the test.html file is loaded into a buffer that is not shown.

How can I test if arguments where passed and not execute the au VimEnter in such a case? Or, alternatively, how can I switch to the buffer holding the file with the given file name.

like image 887
Eric Fortis Avatar asked Jun 06 '11 19:06

Eric Fortis


1 Answers

One can test whether there are any command-line arguments (using the argc() function) and load the previously saved session only when there are not any:

:autocmd VimEnter * if argc() == 0 | source ~/.gvimsession | endif
like image 193
ib. Avatar answered Nov 07 '22 08:11

ib.