When I start gvim I get the errors seen in the bottom of the image. Why?
If I move those functions and lines 57-59 to _vimrc, no errors. Why?
Thanks,
Dick Moores
Image?
> If I move those functions and lines 57-59 to _vimrc, no errors. Why?
Vimrc for reference?
Ben.
Just now I realized that I no longer get that error upon starting
gvim. But I do get it when manually sourcing abbs_and_maps.vim when
it contains those lines.
Dick
Just do what the error message is hinting. Put a ! after :function.
:function! SophHelp()
just like you already have
:function! MapF1()
The ! means it replaces an existing function rather than giving an error.
To make sure a .vimrc is able to be sourced more than once, you need to
do that; you also should make sure you have ! after each :command you
define, and wrap any autocommands in groups something like this:
augroup MyAutoCmds
au!
au ...
au ...
augroup END
The au! command deletes all the autocommands in the group before you
define new ones, so nothing gets defined twice.
Ben.
>Dick Moores wrote:
> > At 10:34 PM 8/22/2008, Dick Moores wrote:
> >> At 09:53 PM 8/22/2008, Ben Schmidt wrote:
> >>
> >>> Dick Moores wrote:
> >>>> From Tip 936
> >>>> (<http://vim.wikia.com/wiki/Disable_F1_built-in_help_key>), I put
> >>>> these 2 functions (see attached image) into my abbs_and_maps.vim
> >>>> file, which is sourced by _vimrc.
> >>>>
> >>>> When I start gvim I get the errors seen in the bottom of the image. Why?
> >>> Image?
> >>>
> >>>> If I move those functions and lines 57-59 to _vimrc, no errors. Why?
> >>> Vimrc for reference?
> >> <http://pastebin.com/f1f10513a>
> >>
> >> _gvimrc: <http://pastebin.com/f67fd948d>
> >
> > Just now I realized that I no longer get that error upon starting
> > gvim. But I do get it when manually sourcing abbs_and_maps.vim when
> > it contains those lines.
>
>Just do what the error message is hinting. Put a ! after :function.
>
>:function! SophHelp()
>
>just like you already have
>
>:function! MapF1()
>
>The ! means it replaces an existing function rather than giving an error.
Done. And the error has disappeared.
>To make sure a .vimrc is able to be sourced more than once, you need to
>do that; you also should make sure you have ! after each :command you
>define, and wrap any autocommands in groups something like this:
>
>augroup MyAutoCmds
>au!
>au ...
>au ...
>augroup END
>
>The au! command deletes all the autocommands in the group before you
>define new ones, so nothing gets defined twice.
OK. Done. Thanks very much for the info about what to do. I still
have the question of why defining a function more than once is a problem.
Dick
So you won't accidentally replace a function (which would cause a mysterious error
in some other operation). You can have quite a lot of scripts in quite a lot of
different places, and it would be reasonably easy to have a name conflict.
John
Ah, replace a different function that has the same name. OK, so given
2 functions foo() -- in the 2nd foo(), a '!' after 'function' (the
keyword that begins a function), would prevent the 2nd function from
being defined. Without a ''!' the 2nd function would cause the 1st to
become non-functioning. Have I got it?
Dick
Back to front I'm afraid!
:so a.vim
:so b.vim
Suppose a.vim uses "function foo" and so does b.vim. The second (b.vim) will NOT be
defined (you will get an error because you are trying to change the existing
definition (even if changing it to the same thing).
However, if a.vim and b.vim use "function! foo" then the second will silently
overwrite the first.
The same reasoning applies if you just do:
:so a.vim
:so a.vim
John
Ah. Thanks for straightening me out, John.
Dick
If you define two _different_ functions with the same name, this warns
you that maybe you ought to give one of them a different name, not only
where it is defined, but wherever it is called.
Best regards,
Tony.
--
"I'm defending her honor, which is more than she ever did."