On Jan 20, 2015 11:36 AM, "Steve Litt" <[email protected]> wrote: > > On Mon, 19 Jan 2015 22:50:49 -0600 > Tim Chase <[email protected]> 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 '!'. 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
