I'm trying to understand what does exclamation mark after autocommands mean.
Sometimes it is possible to see something like this:
function! LangSpecificOptions() if (&filetype == 'markdown' || &filetype == 'html') set wrap else set nowrap endif endfunction autocmd! BufReadPost,BufNewFile * call LangSpecificOptions()
I already found what "!" means when placed after the function:
Bao Niu: I am learning Vimscript and I wonder if there is any difference between writing "function!" vs. "function"? What is that exclamation point for here?
Tim Chase: 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.
However, I haven't found similar explanation for autocommands.
As it correctly stated in comments by @mass, "!" after autocommands mean that this autocommand should be removed. Well, then another question:
What's the purpose of removing autocommands?