微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Vim – 如何在启动vim时立即运行命令?

我有一个插件(FindFile.vim)需要运行:FindFileCache。每当我开始vim收集文件缓存快速打开..我必须运行这个每次我启动vim虽然。

我怎么可以写一个运行一次,每次vim启动的命令?

保存配置的最好的地方是.vimrc
文件。但是,它的来源太早,检查:h startup:
At startup,Vim checks environment variables and files and sets values
accordingly.  Vim proceeds in this order:

1. Set the 'shell' and 'term' option                *SHELL* *COMSPEC* *TERM*
2. Process the arguments
3. Execute Ex commands,from environment variables and/or files *vimrc* *exrc*
4. Load the plugin scripts.                                 *load-plugins*
5. Set 'shellpipe' and 'shellredir'
6. Set 'updatecount' to zero,if "-n" command argument used
7. Set binary options
8. Perform GUI initializations
9. Read the viminfo file
10. Read the quickfix file
11. Open all windows
12. Execute startup commands

如你所见,您的.vimrc将在插件之前加载。如果你放
你的:FindFileCache。在其中将发生错误,因为该命令
退出(但是,一旦插件在步骤4中加载,将存在)。

为了解决这个问题,而不是直接执行命令,创建一个
自动命令。正如你可能已经知道,自动命令执行一些
事件发生时的命令。在这种情况下,VimEnter事件看起来
适当(从:h VImEnter):

*VimEnter*
VimEnter                    After doing all the startup stuff,including
                            loading .vimrc files,executing the "-c cmd"
                            arguments,creating all windows and loading
                            the buffers in them.

然后,只需将此行在.vimrc中:

autocmd VimEnter * FindFileCache .

原文地址:https://www.jb51.cc/vim/391708.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐