Google Vimscript Style Guide

Revision 1.1

Nate Soares
Artemis Sparks
David Barnett

Each style point has a summary for which additional information is available by toggling the accompanying arrow button that looks this way: ▶. You may toggle all summaries with the big arrow button:

▶ Toggle all summaries
Table of Contents

Background

This is a casual version of the vimscript style guide, because vimscript is a casual language. When submitting vim plugin code, you must adhere to these rules. For clarifications, justifications, and explanations about the finer points of vimscript, please refer to the heavy guide.

Portability

It's hard to get vimscript right. Many commands depend upon the user's settings. By following these guidelines, you can hope to make your scripts portable.

Strings

link ▶
Prefer single quoted strings

Matching Strings

link ▶
Use the =~# or =~? operator families over the =~ family.

Regular Expressions

link ▶
Prefix all regexes with \m\C.

Dangerous commands

link ▶
Avoid commands with unintended side effects.

Fragile commands

link ▶
Avoid commands that rely on user settings.

Catching Exceptions

link ▶
Match error codes, not error text.

General Guidelines

Messaging

link ▶
Message the user infrequently.

Type checking

link ▶
Use strict and explicit checks where possible.

Python

link ▶
Use sparingly.

Other Languages

link ▶
Use vimscript instead.

Boilerplate

link ▶
Use maktaba.

Plugin layout

link ▶
Organize functionality into modular plugins

Functions

link ▶
In the autoload/ directory, defined with [!] and [abort].

Commands

link ▶
In the plugin/commands.vim or under the ftplugin/ directory, defined without [!].

Autocommands

link ▶
Place them in plugin/autocmds.vim, within augroups.

Mappings

link ▶
Place them in plugin/mappings.vim, using maktaba#plugin#MapPrefix to get a prefix.

Settings

link ▶
Change settings locally

Style

Follow google style conventions. When in doubt, treat vimscript style like python style.

Whitespace

link ▶
Similar to python.

Naming

link ▶

In general, use plugin-names-like-this, FunctionNamesLikeThis, CommandNamesLikeThis, augroup_names_like_this, variable_names_like_this.

Always prefix variables with their scope.

Revision 1.1

Nate Soares
Artemis Sparks
David Barnett