Why do I get E122?

34 views
Skip to first unread message

Dick Moores

unread,
Aug 22, 2008, 11:25:29 PM8/22/08
to vim...@googlegroups.com
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?

If I move those functions and lines 57-59 to _vimrc, no errors. Why?

Thanks,

Dick Moores

Ben Schmidt

unread,
Aug 23, 2008, 12:53:10 AM8/23/08
to vim...@googlegroups.com
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?

Ben.


Dick Moores

unread,
Aug 23, 2008, 1:34:52 AM8/23/08
to vim...@googlegroups.com
vim_error.jpg

Dick Moores

unread,
Aug 23, 2008, 1:46:41 AM8/23/08
to vim...@googlegroups.com

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

Ben Schmidt

unread,
Aug 23, 2008, 2:11:53 AM8/23/08
to vim...@googlegroups.com

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

unread,
Aug 23, 2008, 3:43:51 AM8/23/08
to vim...@googlegroups.com
At 11:11 PM 8/22/2008, Ben Schmidt wrote:

>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

John Beckett

unread,
Aug 23, 2008, 4:18:23 AM8/23/08
to vim...@googlegroups.com
Dick Moores wrote:
> I still have the question of why defining a function
> more than once is a problem.

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

Dick Moores

unread,
Aug 23, 2008, 4:56:26 AM8/23/08
to vim...@googlegroups.com

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


John Beckett

unread,
Aug 23, 2008, 8:12:22 AM8/23/08
to vim...@googlegroups.com
Dick Moores wrote:
> 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?

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

Dick Moores

unread,
Aug 23, 2008, 8:59:41 AM8/23/08
to vim...@googlegroups.com

Ah. Thanks for straightening me out, John.

Dick

Tony Mechelynck

unread,
Aug 23, 2008, 10:07:29 AM8/23/08
to vim...@googlegroups.com
On 23/08/08 09:43, Dick Moores wrote:
[...]

> 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

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

Reply all
Reply to author
Forward
0 new messages