Monday, January 19, 2015

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

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


--
--
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: