简体   繁体   中英

Commands that work in vim don't work in vimrc

I'm using Pathogen to set up bundles in vim. One such bundle I use is vdebug . I want to set vdebug so it doesn't have a "server" option by default. Within vim, I can do that with either one of

VdebugOpt server ""
let g:vdebug_options['server'] = ""

But if I set one of those commands in my ~/.vimrc, when I first start vim it fails. Here's a very simple .vimrc that reproduces the problem:

execute pathogen#infect()
syntax on
filetype plugin indent on
call pathogen#helptags()
VdebugOpt server ""

With that, I get

Error detected while processing /home/editor/.vimrc:
line    5:
E492: Not an editor command: VdebugOpt server ""

Or, if I change the last line to

let g:vdebug_options['server'] = ''

I get

Error detected while processing /home/editor/.vimrc:
line    5:
E121: Undefined variable: g:vdebug_options

But once vim is started, either one of those commands works. What is going on to cause this discrepancy, and how can I set the default I want for vim on startup?

You can see in :h initialization that Vim will, at startup, run .vimrc (step 3), then run plugins (step 4). VdebugOpt is simply not defined in .vimrc , nor is g:vdebug_options (so you can't add a new option).

However, you can define g:vdebug_options :

let g:vdebug_options = {
  \   'server' = ''
  \ }

or equivalently

let g:vdebug_options = {}
let g:vdebug_options['server'] = ''

As noted in another answer, plugin commands are not defined yet when the .vimrc is running. You can work around this by invoking the command in a VimEnter autocmd:

autocmd VimEnter * VdebugOpt server ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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