在 .vimrc 中,如何测试是否在调用时向 Vim 提供了任何文件名参数? [英] In .vimrc, how to test whether any filename arguments are given to Vim at invocation?
本文介绍了在 .vimrc 中,如何测试是否在调用时向 Vim 提供了任何文件名参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题的答案仅在 GUI 中使用 vim 会话? 建议使用
au VimLeave * mksession! ~/.gvimsession
au VimEnter * source ~/.gvimsession
我的问题是当我启动 Vim 时,比如说,通过发出 $ gvim test.html
,test.html
文件被加载到一个未显示的缓冲区中.
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.
在这种情况下,我如何测试参数是否通过而不执行 au VimEnter
?或者,我如何切换到保存具有给定文件名的文件的缓冲区.
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.
推荐答案
可以测试是否有任何命令行参数(使用argc()
函数)并仅在没有:
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
这篇关于在 .vimrc 中,如何测试是否在调用时向 Vim 提供了任何文件名参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文