On Sun, May 14, 2006 at 06:41:39PM -0700, Gerald Lai wrote:
> 
> Encase your function like this:
> 
> if !exists("*Source_vimrc")
>   function Source_vimrc()
>   ...
>   endfunction
> endif
> 
> The reason you're getting the error is because you're sourcing the file
> (vimrc) that produced/will override the function (Source_vimrc) you're
> using at the moment.
> 
> A few words of advice to source your vimrc cleanly:
> 
>   1. Define your functions in vimrc with "function!" so that when
>      sourced again, the functions will be overwritten.
> 
>   2. Keep your autocmds in an augroup so that if it's sourced again, you
>      can delete the augroup and redefine it instead of adding more of
>      the same autocmds.
> 
>   3. If you're using the FuncUndefined autocmd, delete those functions
>      that have been defined before.

     Those are all good suggestions (although testing
exists("*Source_vimrc") seems a little complicated).  One more
possibility is to put all function definitions, along with anything else
that never needs to be re-done, below a few lines like these:

" Skip the rest of the file if it has already been re-loaded.
if exists("s:deja_vu")
  finish
endif
let s:deja_vu = 1

function Source_vimrc() " no need for the !, this should never be read twice.
...

     BTW, another post on this thread pointed out that your vimrc file
knows its own name.  As of vim 7.0, this name is also stored in the
$MYVIMRC environment variable.

HTH                                     --Benji Fisher

Reply via email to