1

I'm using Linux, Vim (nox) 9.0, and Neovim 0.9.4; I have both environments synchronized.

What would prevent a .vim file in ~/.vim/autoload/ or ~/.config/nvim/autoload/ from autoloading?

The only script that's autoloading for me is plug.vim None of my custom scripts are loading. I get no errors.

1
  • 1
    Do you still have something open in your question? How can we help you further? If one answer address your problem maybe could you accept it using the v button next to the arrow voting buttons. It allow the question to rest :-) Nov 14, 2023 at 14:33

1 Answer 1

1

A script in autoload is loaded when a function that is defined in your autoload script is called.

The autoload scripts have been introduced to optimize the Vim startup time. Instead of loading all the Vim scripts to make all the plugin functions available some Vim scripts loading are postponed to the moment a function that is defined in it is called.

Suppose you have a file: ~/.vim/autoload/foo.vim with the following content:

function! foo#bar()
  echom 'foo#bar()'
endfunction

The script autoload/foo.vim will only be loaded when another scripts or call command calls foo#bar()

:call foo#bar()

More information with: :help autoload

Remark: If you want your script to be sourced at startup unconditionally you can put it in the plugin folder.

More information with :help standard-plugin

4
  • 1
    Ok. It makes sense. My two scripts define some functions but also contain the keybindings. Since the keybindings live in the script file, and the script file isn't run until a function therein is used, that would explain why my scripts aren't working. They're never loaded and the bindings are never defined. I suppose the simple solution is to source the two scripts in my RC.
    – LiamF
    Nov 13, 2023 at 20:45
  • 1
    If you want a script to be sourced you could put it in the plugin folder. I would put the keybinding in a plugin script and the functions in the autoload script. Like this the autoload script is loaded only when the keymappings are first used and don't slow down the Vim startup :-) Nov 13, 2023 at 20:51
  • 1
    Does nvim acknowledge the plugin folder? And if so, does it truly automatically source files there? (Or will I still need a source ... line in my rc/init files?)
    – LiamF
    Nov 14, 2023 at 5:10
  • 1
    It does but and you don't need the explicitly source it's content more information with :help standard-plugin Nov 14, 2023 at 5:49

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.