Vim e518: unknown option:

I have a text file on a unix system. The following text file content creates a 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 will disappear. But the strange thing is that even with an empty ~/.vimrc file, an error appears.

I understand that this is because the line starts with vi: that the error was created, but I do not understand why and how to fix it.

+8
vim
source share
3 answers

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

The reason it doesn't work when you don't have ~/.vimrc is because Vim requires the 'nocompatible' parameter to be set for simulation, by default, because it is a Vim-specific function. The existence of ~/.vimrc sufficient for Vim to switch from vi-compatible mode to nocompatible, though, which will lead to the installation of the 'modeline' option.

In the future, you can easily find help topics in Vim through :help topic<Tab> . In this case :help modeline<Tab> would provide you with several topics that could explain this function and how to control it.

+9
source share

You can turn off model processing with

 :set nomodeline 

See :help modeline details.

+10
source share

In the section :help auto-setting you will 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, maybe your ~ / .vimrc has set nomodeline .

Reading the line vi: bad line tries to set the bad and line option, which cannot be set, therefore, an error.

EDIT . As stated in Jamasan's answer (+1), the modeline parameter is set via the nocompatible setting due to the simple existence of ~/.vimrc .

+1
source share

All Articles