1

I have the following in my vimrc:

call plug#begin()
Plug 'https://github.com/vim-scripts/RltvNmbr.vim'
call plug#end()

set number
RltvNmbr

When I type :so % while in my vimrc, it will turn on the relative line numbers with no error message.

However if I :q and reopen that same vimrc, I get:

E492: Not an editor command: RltvNmbr
Press ENTER or type command to continue

I was under the understanding that opening a file in vim automatically sources the vimrc. Thus I do not understand why I get the above error when opening a file in vim, but not when manually sourcing the vimrc.

5
  • 2
    No, plugins are sourced after your init scripts. Check the order in :h startup or check the output of the :scriptnames command. So perhaps you need to use an VimEnter autocommand to call the RltvNmbr command? Jan 21, 2023 at 19:35
  • That's good to know! I did try au VimEnter RltvNmbr but that didn't seem to do anything. I have other plugin-related commands being executed after my call plug#end() and those don't seem to be causing any problems...
    – brianxk
    Jan 21, 2023 at 19:51
  • 2
    it should be au VimEnter * RltvNmbr Jan 21, 2023 at 19:56
  • That fixed it. Thank you very much stranger! Edit: How come this command failed but other plugin-related commands worked following my call to call plug#end()?
    – brianxk
    Jan 21, 2023 at 19:59
  • 1
    @brianxk that depends on what those commands were. User commands would suffer the same problem, but calling autoload functions or setting variables probably won’t
    – D. Ben Knoble
    Jan 22, 2023 at 17:27

1 Answer 1

1

As Christian Brabandt pointed out, the plugin was being sourced after the vimrc when opening the vimrc from scratch (vs. :so % while the vimrc is still open).

Changing:

RltvNmbr

to:

au VimEnter * RltvNmbr

did the trick.

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.