Where should users put custom vim functions?

Cyker

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?

Ingo Karkat

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Meteor: Where should we put common functions?

From Dev

Where should I put functions in Javascript code?

From Dev

Where to put custom global functions in CakePHP?

From Dev

Symfony2 - Where should I put files uploaded by users?

From Dev

Symfony2 - Where should I put files uploaded by users?

From Dev

Where should I put completer.complete() in this series of Future functions?

From Dev

Where should I put test utility functions in Rust?

From Dev

Where should I put the code for functions used in Meteor.startup?

From Dev

Where should I put a custom method for a existing class in rails?

From Dev

Gradle android: Where should I put my custom task?

From Dev

Where should i put the function?

From Dev

Where should the credentials for mysql be put?

From Dev

.tolowerCase() Where should I put it?

From Dev

Where should I put the codes?

From Dev

Where to put the customized functions for snippet?

From Dev

Vim finding where functions and such are declared

From Dev

Where on a bootable Windows PE USB drive should I put custom executables?

From Dev

Where should I put automapper code?

From Dev

Where should I put this code in Laravel?

From Dev

Where should I put removeObserver from NSNotification

From Dev

Composer: where should I put the "vendor" folder?

From Dev

Where should I put the "clear: both"?

From Dev

Where should I put navigation code?

From Dev

Where should I put unhandled exception handler?

From Dev

Where should I put interfaces and implementations

From Dev

Where should I put the images for the Java app?

From Dev

Where should I put my bash scripts

From Dev

Where should I put my defaults?

From Dev

Where should I put automapper code?

Related Related

HotTag

Archive