Home

modelines

Modelines are lines embedded in a text file that allow a text editor to apply settings automatically when the file is opened. They are most commonly associated with Vi and Vim, but variants exist in other editors. A modeline specifies options such as tab stops, indentation method, text width, encoding, line endings, and filetype.

In Vim, a modeline is a line that starts with vim: or vi:, and is recognized if

Security considerations: Modelines can execute editor commands, which creates a potential risk if the file is

Emacs and other editors offer similar per-file configuration mechanisms, such as Local Variables blocks at the

See also: Local variables, file metadata, Vim modeline security.

it
appears
within
the
first
five
or
last
five
lines
of
the
file.
A
typical
Vim
modeline
uses
the
set
command,
for
example:
vim:
set
ts=4
sw=4
expandtab
et:
or
vim:
set
ft=python
ts=4
sw=4:
The
colon
is
used
to
delimit
commands;
multiple
options
can
be
listed
separated
by
spaces.
The
editor
applies
these
settings
on
opening
the
file.
from
an
untrusted
source.
Many
editors
provide
a
toggle
to
disable
modelines
(for
example,
set
nomodeline
in
Vim)
or
restrict
the
commands
that
can
be
run.
Newer
configurations
may
enable
strict
parsing
or
disable
evaluation
of
expressions
within
modelines
by
default.
end
of
a
file,
but
they
are
not
called
modelines
in
the
Vim
sense.