Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim e518: unknown option:

Tags:

vim

I have a text file on a unix system. The following text file content creates the problem:

good: ok line
vi: bad line
ok: ok line

So if I run: vim test.txt, I get the following error:

"test.txt" 3L, 39C
Error detected while processing modelines:
line    2:
E518: Unknown option: bad
Press ENTER or type command to continue

If I delete my ~/.vimrc, the error disappears. But what is weird is that, even with an empty ~/.vimrc file, the error appears.

I understand that it's because the line starts with vi: that the error is created, but I don't understand why or how to fix this.

like image 685
Danosaure Avatar asked Dec 20 '11 22:12

Danosaure


3 Answers

The vi: bad line line is in a format that Vim recognizes as a modeline, as mentioned in the error message. Modelines allow one to set options within a file.

The reason it isn't triggered when you don't have a ~/.vimrc is because Vim requires you have 'nocompatible' set for modelines to be enabled by default, since it is a Vim-specific feature. The existence of ~/.vimrc is enough for Vim to switch from vi-compatible mode to nocompatible, though, which will result in the 'modeline' option also being set.

For future reference, you can easily find help topics in Vim via :help topic<Tab>. In this case, :help modeline<Tab> would have given you a few topics to look into which explain this feature and how to control it.

like image 119
jamessan Avatar answered Oct 31 '22 23:10

jamessan


You could turn off modeline processing with

:set nomodeline

See :help modeline for more information.

like image 45
Greg Hewgill Avatar answered Oct 31 '22 22:10

Greg Hewgill


Under :help auto-setting you find this paragraph:

3. If you start editing a new file, and the 'modeline' option is on, a
   number of lines at the beginning and end of the file are checked for
   modelines.  This is explained here. 

There are two forms of modelines.  The first form:
    [text]{white}{vi:|vim:|ex:}[white]{options}

[text]      any text or empty
{white}     at least one blank character (<Space> or <Tab>)
{vi:|vim:|ex:}  the string "vi:", "vim:" or "ex:"
[white]     optional white space
{options}   a list of option settings, separated with white space or ':',
        where each part between ':' is the argument for a ":set"
        command (can be empty)

Example:
   vi:noai:sw=3 ts=6 ~

The second form (this is compatible with some versions of Vi):

    [text]{white}{vi:|vim:|ex:}[white]se[t] {options}:[text]

[text]      any text or empty
{white}     at least one blank character (<Space> or <Tab>)
{vi:|vim:|ex:}  the string "vi:", "vim:" or "ex:"
[white]     optional white space
se[t]       the string "set " or "se " (note the space)
{options}   a list of options, separated with white space, which is the
        argument for a ":set" command
:       a colon
[text]      any text or empty

Example:
   /* vim: set ai tw=75: */ ~

The white space before {vi:|vim:|ex:} is required.  This minimizes the chance
that a normal word like "lex:" is caught.  There is one exception: "vi:" and
"vim:" can also be at the start of the line (for compatibility with version
3.0).  Using "ex:" at the start of the line will be ignored (this could be
short for "example:").

So, probably, in your ~/.vimrc you have a set nomodeline.

The line reading vi: bad line tries to set the option bad and line which cannot be set, hence the error.

EDIT: As pointed out by jamessan'S answer (+1), the modeline option is set through the setting of nocompatible by the mere existence of ~/.vimrc.

like image 1
René Nyffenegger Avatar answered Oct 31 '22 22:10

René Nyffenegger