1

I'm forking an old vim plugin (effectively dead since 2018) that needed some love. Once I got to the .vim file, I noticed that the functions were all defined in there, which made the file unreasonably huge and messy. Is there any way to move these functions to different files for the sake of maintenance?

2
  • 2
    for vimscript, there are autoloadable functions, see :h autoload, for vim9script you can use imports see :h vim9-import Dec 30, 2021 at 13:14
  • Welcome to Vi and Vim! Yeah, autoload is what you want... In short, you need to store them somewhere under an autoload/ directory and call them using a my#plg#myfunc() syntax (assuming myfunc() is defined in autoload/my/plg.vim). For maximum efficiency (during Vim startup), make sure functions from your auto-loaded file will only be called from mappings or user-commands, autocommands, filetype-specific plugins. That way, the autoload file will not be loaded at startup, but only when it's actually needed...
    – filbranden
    Dec 30, 2021 at 18:26

1 Answer 1

Your Answer

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

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