加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 16:36:14 所属栏目:安全 来源:网络整理
导读:我有一个插件(FindFile.vim)需要运行:FindFileCache。每当我开始vim收集文件缓存快速打开..我必须运行这个每次我启动vim虽然。 我怎么可以写一个运行一次,每次vim启动的命令? 保存配置的最好的地方是.vimrc 文件。但是,它的来源太早,检查:h startup:
我有一个插件(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 .

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读