From 3b16d4cf2c54d7490a020d63b8e1761052777a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sweidan=20Om=C3=A1r?= Date: Thu, 20 Jul 2023 13:05:28 +0200 Subject: [PATCH] Update vimscript.md (#2008) Added a section on overwriting functions --- vimscript.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vimscript.md b/vimscript.md index 1b241a985..62d763833 100644 --- a/vimscript.md +++ b/vimscript.md @@ -146,6 +146,20 @@ endfunction See: [Functions](http://learnvimscriptthehardway.stevelosh.com/chapters/23.html) +### Overwriting +```vim +function f1() + echo "f1" +endfunction + + +function! f1() + echo "f1 overridden" +endfunction +``` + +If you define two functions with the same name, Vim will throw an error complaining that the function `f1` already exists. To overwrite the previous function with the same name, add a `!` after the function keyword. + ### Namespacing ```vim