Tuesday, January 20, 2015

Re: why "function!" instead of just "function"

Thank you guys, I really appreciate all the useful tips here!

On Tue, Jan 20, 2015 at 9:46 AM, Nikolay Pavlov <zyx.vim@gmail.com> wrote:


2015-01-20 19:42 GMT+03:00 Salman Halim <salmanhalim@gmail.com>:


On Jan 20, 2015 11:36 AM, "Steve Litt" <slitt@troubleshooters.com> wrote:
>
> On Mon, 19 Jan 2015 22:50:49 -0600
> Tim Chase <vim@tim.thechases.com> wrote:
>
> > On 2015-01-19 20:31, Bao Niu wrote:
> > > I am learning Vimscript and I wonder if there is any difference
> > > between writing "function!" vs. "function"? What is that
> > > exclamation point for here?
> >
> > As detailed at
> >
> >   :help E123
> >
> > If a function already exists with the same name as you want to
> > create, the "!" will tell it to overwrite the previously-existing
> > function.  Thus, you might have
> >
> >   function Hello()
> >     echo 'Hello'
> >   endfunction
> >
> > and then want to change it, so you'd use
> >
> >   function! Hello()
> >     echoerr 'Hello'
> >   endfunction
> >
> > to overwrite it.  Because of the behavior, I just use the "!" *every*
> > time that I define a function.  That way, I don't have to think about
> > whether it already exists or not.
> >
> > -tim
>
> Tim,
>
> Thanks for the complete explanation. I always wondered that myself.
>
> SteveT

If you're writing a utility or plugin function that isn't specific to your script, I start with just 'function' as it helps me identify which function names already exist and I might clobber them. Once I know the name I've chosen is truly unique, I add the '!'.


Since you obviously do not test each and every plugin in world you cannot know that this name is truly unique.
 

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/71gztuCIKXI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: