12

Is there a good reason why VimScript functions that I put in my .vimrc or _vimrc have to begin with a capital letter?

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.

| improve this answer | |
  • 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 Mar 20 '15 at 17:37
  • 8
    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. – Peter Rincker Mar 20 '15 at 17:57
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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