Some functions are filetype-specific, and I'm wondering what is the best practice to organize these functions. Should I define them in ftplugin
as script-local functions or put everything in autoload
?
It depends.
First, be pragmatic. If it's just a short function, and only used locally, I have no qualms putting them directly into my ~/.vimrc
, or into a ~/.vim/ftplugin/*.vim
script. The latter one is somewhat inefficient, because the function gets redefined for each opened file that has the same filetype.
You already know about autoload functions, and of course, this is the canonical place to put custom functions. Dogmatic people will insist that (ft-)plugins only contain configuration, mappings, custom commands, and :autocmd
, and all functions be placed in ~/.vim/autoload/
. I would recommend that for any longer function (or sets of functions that call each other), or anything you intend to publish for someone else to reuse.
For filetype plugins, I've adopted the convention of placing such functions into ~/.vim/autoload/ft/{filetype}.vim
, or ~/.vim/autoload/ft/{filetype}/{submodule}.vim
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments