1

First off, just an FYI: I am not that experienced with writing VimScript

I have a plugin that I want to have enabled using its custom Ex command (:RainbowParentheses). Putting that inside my init.vim:

:RainbowParentheses

I found that it does not work and Vim (Neovim) throws an error saying the command is "Not an Editor command". I assume just throwing an Ex command into your vimrc or init.vim would not work. How would I be able to execute an Ex command in my init.vim? Would I be using a VimScript function to enable it if I had several other commands of a similar nature?

4
  • You can and such command. The problem is that the command is probably not yet defined when you call it. Could you try to put at the of your .vimrc file? May 9 at 21:39
  • @VivianDeSmedt Could you please clarify what you mean?
    – UnrealApex
    May 9 at 21:48
  • 2
    Just to be clear, every command in Vimscript is an Ex command.
    – 8bittree
    May 10 at 15:42
  • The VimHelp page was very informative and provided more clarification. Thank you!
    – UnrealApex
    May 10 at 23:49

1 Answer 1

4

I believe @VivianDeSmedt's comment refers to :help startup (notice that the vimrc is executed after files like plugin/*.vim and others have loaded).

In general you cannot use a command until it has been defined. The standard Ex commands (lowercase letters) are all available at any time; for a user-defined command, place the invocation logically after the definition.

For a command defined in your vimrc, this means placing :RainbowParentheses after the :command RainbowParentheses … that defines it.

For a command defined by a plugin, a solution like the following usually works (since VimEnter is triggered at the end of :help startup):

augroup rainbow_parens
  autocmd!
  autocmd VimEnter * RainbowParentheses
augroup end
3
  • Thank you for your help and the explanation! I suggest maybe editing your answer to include links to the Vim help.txt so future users like me can quickly understand some of the things you are referencing.
    – UnrealApex
    May 10 at 4:18
  • 1
    If someone has the web links they are free to add them since anyone can edit @UnrealApex. The commands will work regardless of your internet connection or if you are on your phone or something. I don’t add the links because I don’t use them, but I’m happy to approve edits that add them.
    – D. Ben Knoble
    May 10 at 16:03
  • If you want to you can, if no one edits in a couple of days I could just do the edits myself.
    – UnrealApex
    May 10 at 23:48

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.