Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between "function" and "function!" in VIM?

Tags:

I beheld quite a few usage of "function!" in others vimrc files, but there is no easy-to-find documentation of "function!".

What's the difference between "function" and "function!"?

like image 556
Morgan Cheng Avatar asked Nov 28 '09 12:11

Morgan Cheng


People also ask

What is the function of vim?

Vimscript is a powerful scripting language that lets you modify and extend the Vim editor. You can use it to create new tools, simplify common tasks, and even rework existing features of the editor.

What does echo do in Vim?

Plain old :echo will print output, but it will often disappear by the time your script is done. Using :echom will save the output and let you run :messages to view it later.

How do I run a script in vim?

You can always execute Vimscript by running each command in command mode (the one you prefix with : ), or by executing the file with commands using a :source command. Historically, Vim scripts have a . vim extension. Here, :so is a short version of :source , and % refers to the currently open file.


2 Answers

:help user-functions

When a function by this name already exists and [!] is
not used an error message is given. When [!] is used,
an existing function is silently replaced. Unless it
is currently being executed, that is an error.

like image 82
Egor Rogov Avatar answered Oct 06 '22 01:10

Egor Rogov


In general, it suppresses the messages the command may spit out.

For instance, using function!, you can redeclare an already defined function.

like image 34
mmx Avatar answered Oct 06 '22 01:10

mmx