kojiro
kojiro

Reputation: 77187

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?

Upvotes: 1

Views: 507

Answers (2)

Ben
Ben

Reputation: 8905

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 ""

Upvotes: 0

Amadan
Amadan

Reputation: 198526

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'] = ''

Upvotes: 3

Related Questions