Is there a good reason why VimScript functions that I put in my .vimrc
or _vimrc
have to begin with a capital letter?
2 Answers
To quote :help user-functions
The function name must start with an uppercase letter, to avoid confusion with builtin functions.
The same restriction is placed on user-defined commands, although there are a few builtin commands (:N[ext]
, :P[rint]
, :X
) which start with capital letters.
-
1Ah! It all makes sense now. But how annoying to a former Java programmer, and to restate the command in the middle,
:P
oh well...now at least I have a reason why this is the case.– leeand00Commented Mar 20, 2015 at 17:37 -
10But there is more! you can use a lowercase function name you just need to prefix it with
s:
making it a script specific function. See:h local-functions
. You can also use autoload functions which don't have this requirement. See:h autoload-functions
. Commented Mar 20, 2015 at 17:57
Old style public function names do indeed have to start with a capital letter. However script function names s:getSNR()
, or autoloaded function names (lh#option#get()
) do not -- I do it more and more often in my plugins.