开发者

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

开发者 https://www.devze.com 2023-03-11 06:54 出处:网络
The answer to the question Using开发者_StackOverflow vim Sessions Only With GUI? suggests using au VimLeave * mksession! ~/.gvimsession

The answer to the question Using开发者_StackOverflow 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
0

精彩评论

暂无评论...
验证码 换一张
取 消