Some versions of
When that option is set in your
you can store setup commands at the top or bottom of any file you edit.
When you start the editor, it will read the setup commands and run them.
This is a lot like having a separate
for each file you edit.
Modelines can be a security problem.
If any troublemakers should edit your files and change your modelines, think
about the difficulties they can cause you.
Most newer versions of
disable modelines by default.
Here's a sample file - a
shell script (
with a modeline on the second line:
# vi:set number wrapmargin=0 autoindent showmatch:
while read line
The modeline has
, the shell's comment character, at the start
of it - so, the shell will ignore the line but
will still read it.
This is only necessary in a shell script, but it demonstrates that the
modeline need not start in column 1. The modeline itself
consists of a space or tab, the string
commands to be executed, and a closing colon. Both the space or tab
before the modeline, and the closing colon are important - they
tell the editor where the modeline begins and ends. You
can put modelines on the first five or last five lines of a file
When you start
on the file shown in the example above,
it sets the options
Any time you open a file with a modeline,
changes the file
status to "modified"-even if you haven't actually made any changes.
To leave the file without writing it, you have to use the
This is a hassle when you use UNIX tools that depend on a file's
modification time, like
especially if you also have the
To find out whether your version of
supports modelines - and
whether the option is called
a list of all options with the command
If the option is available, but not set, you'll see
as one of the options. Put the command
file to enable the option.
Unfortunately, some versions list the option but don't support it!