14

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 2

12

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.

2
  • 1
    Ah! 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.
    – leeand00
    Commented Mar 20, 2015 at 17:37
  • 10
    But 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
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.