简体   繁体   English

为什么vim在vimrc中无法识别插件命令,但是在运行时会识别出插件命令?

[英]Why won't vim recognise a plugin command in the vimrc, but it will recognise it when running?

I've installed the vim-gitgutter plugin with pathogen. 我已经安装了带有病原体的vim-gitgutter插件 I can type :GitGutterLineHighlightsEnable from inside vim and line highlights are turned on, great. 我可以从vim里面输入:GitGutterLineHighlightsEnable ,并且打开行高亮显示,太好了。

But I want line highlights to be automatically enabled at startup, so I added the command to my ~/.vimrc . 但是我希望在启动时自动启用行高亮显示,因此我将命令添加到了~/.vimrc However when I start vim, I get "E492: Not an editor command: GitGutterLineHighlightsEnable". 但是,当我启动vim时,出现“ E492:不是编辑器命令:GitGutterLineHighlightsEnable”的信息。 Once vim has started up, I can run the command. 一旦vim启动,我就可以运行命令了。

My vimrc looks like this: 我的vimrc看起来像这样:

execute pathogen#infect()
colorscheme railscasts

  .. snip tabs and colors etc ..

GitGutterLineHighlightsEnable
hi GitGutterAddLine guibg=#222F22
hi GitGutterChangeLine guibg=#222239
hi GitGutterDeleteLine guibg=#2F2222

Use 采用

let g:gitgutter_highlight_lines = 1

instead of 代替

GitGutterLineHighlightsEnable

Figured it out. 弄清楚了。

.vimrc is executed before plugins are loaded. .vimrc 加载插件之前执行。 From this related question , I changed the commands to: 这个相关问题开始 ,我将命令更改为:

autocmd VimEnter * GitGutterLineHighlightsEnable

This executes the command after vim has started up. vim启动后,这将执行命令。

As you determined yourself, plugins are processed after the .vimrc. 如您所愿,插件将在.vimrc之后处理。

What you can do if you don't like using a VimEnter autocmd, is put a file in your ~/.vim/after/plugin directory for any commands that should run after plugins are loaded. 如果您不喜欢使用VimEnter autocmd,可以执行的操作是将一个文件放置在〜/ .vim / after / plugin目录中,以获取加载插件后应运行的所有命令。

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

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