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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.