This is the in-depth vimscript guide. If you're just a casual user looking to write a plugin, the abbreviated style guide is for you.

This rather rotund guide dives into justifications and clarifications. It provides an idealized set of rules that are rather too draconian to push on casual scripters.

It's for users who want to know why certain decisions were made in the abbreviated guide and who want to learn a thing or two about using vimscript safely.

Fair warning: Vimscript is a maddening abyss. When you gaze into it, it gazes also into you. Proceed with caution.

Vim is highly configurable. Users can change many of the default settings, including the case sensitivity, the regular expression rules, the substitution rules, and more. In order for your vimscript to work for all users, follow these guidelines:

In general, guard all commands and functions against user settings.

All other language features are fair game.

Separate library-providing plugins from command-providing plugins.

Many plugins provide either user functionality (commands, autocommands, etc) or an API (of autoloaded functions) but not both. This separation is encouraged, as it allows other plugins to pull in a library without also pulling in commands, setting changes, and other plugin functionality that affects the end user.

Don't clobber user settings. Provide as much configurability as possible: that's what Vim's all about.

Follow google-wide style conventions. Mimic google python style when in doubt.

Use vimdoc.

Provide help files generated by vimdoc. Write documentation in .vim files in conformance with the vimdoc standards and include fields like "description" and "author" in the addon-info.json file (see the VAM documentation).

Follow google-wide conventions.

plugin-names-like-this, FunctionNamesLikeThis, CommandNamesLikeThis, augroup_names_like_this, variable_names_like_this.

Prefix all variables with their scope.

Prefer single quotes.

Prefer single quoted strings. Specifically, in order of precedence:

Prefer long names. Set settings locally.

Vim plugins should provide any or all of the following: Commands, Autocommands, Functions, Statusline Flags, and Mappings.

Declare dependencies in addon-info.json and use maktaba.

Declaring dependencies in addon-info.json allows conformant plugin managers (like VAM) to ensure dependencies are installed. See the VAM documentation for details.

Calling maktaba#library#Require from dependent code at runtime ensurestoto

that dependencies have been installed and that they don't include unsafe non-library files.

Use <plugin-name>#status#Status() or its finer-grained variants tototo

provide statusline flags.

Following is a convention for exposing statusline flags to the user. A plugin should never modify the user's statusline except for when that is the only purpose of the plugin (powerline, etc.).

These are commands which can only be used by a limited number of plugins, and should not in general be used by yours.

Lay out plugin/ files in the following sections, if applicable, separated by two blank lines:

Lay out autoload/ files in the following sections, if applicable, separated by two blank lines:

This is recommended convention and is not enforced.

Use the following shortcuts:

This section plumbs some of the darker corners of vimscript, explaining the language pathologies that you wish you didn't have to know.

If you don't support vi-compatibility mode, fail gracefully.

When compatible is set, many vim features are not available. The vim feature which most commonly affects vimscript authors is line continuations.

If you want your plugin to work in vim with vi compatibility on, you will need to save the compatibility options at the beginning of each plugin file, clear them, and restore them at the end of each plugin file. See :help use-cpo-save for details.

Plugins that depend on maktaba generally don't need to worry about compatible mode since maktaba currently just disables it, printing a warning.

Revision 1.1

Nate Soares
Joshua Hoak
David Barnett