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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With