Vim Configuration and Settings

So far, this is a collection of bits and pieces about configuring Vim.


The options can be set and read like variables with the ex command :set. A single :set shows all options that differ from their default value. An actual setting can be inspected with :set {option}?. There are toggle options, string and number values. Toggle options are set with :set {toggle} and reset with :set no{toggle}. The other options are set with :set {option}={value}. Options that are a list of flag characters can be modified by adding or removing dedicated flags with :set {flags}+=a or :set {flags}-=b (to avoid overwriting the whole set of flags). Many other operations are possible (e.g. inverting a toggle option), refer to the help page. With :verbose set {option}?, vim displays where an option was set.

There are global settings and local settings only for the current buffer


See: :help options

Config files

The main config file is $HOME/.vimrc. If the option exrc is set, vim also reads an existing file .vimrc in the working directory. It can be used to override some settings on a per-project base.

See: :help vimrc


Modelines are per-file settings. By default, vim checks the first and last 5 lines for a modeline. It usually begins with a comment sign (depending on the programming language e.g. // for C, # for Bash and Python, % for LaTeX). Then follows the marker vim:. Only the set command is supported to avoid hostile text files manipulating your editor and system.

Two forms are supported:

// vim: sw=3 ts=6
/* vim: set sw=3 ts=6 : */

The first form lists only the options to set separated either by space or colon. The second form begins with set and ends with a colon that can be followed by other text, for example a comment terminator.

See: :help modeline

Further reading

Some packages with default configurations or to manage the config file will be described in an article about plugins.