简体   繁体   English

在.vimrc中,如何测试调用时Vim是否有文件名arguments?

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

The answer to the question Using vim Sessions Only With GUI? 仅在 GUI 中使用 vim 会话问题的答案? 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.我的问题是当我启动 Vim 时,比如说,通过发出$ gvim test.htmltest.html文件被加载到未显示的缓冲区中。

How can I test if arguments where passed and not execute the au VimEnter in such a case?在这种情况下,如何测试 arguments 是否通过并且不执行au VimEnter VimEnter? 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:可以测试是否有命令行 arguments(使用argc()函数),只有在没有的时候才加载之前保存的 session:

:autocmd VimEnter * if argc() == 0 | source ~/.gvimsession | endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM