vim e518:未知选项:

时间:2011-12-20 22:55:04

标签: vim

我在unix系统上有一个文本文件。以下文本文件内容会产生问题:

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

因此,如果我运行:vim test.txt,我会收到以下错误:

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

如果我删除~/.vimrc,则错误消失。但奇怪的是,即使有一个空的~/.vimrc文件,也会出现错误。

我理解这是因为该行以vi:开头创建了错误,但我不明白为什么或如何解决这个问题。

3 个答案:

答案 0 :(得分:14)

vi: bad line行采用Vim识别为modeline的格式,如错误消息中所述。 Modelines允许用户在文件中设置选项。

当您没有~/.vimrc时未触发它的原因是因为Vim要求您为默认情况下启用的模型设置'nocompatible',因为它是特定于Vim的功能。 ~/.vimrc的存在足以让Vim从vi兼容模式切换到nocompatible,这将导致'modeline'选项也被设置。

为了将来参考,您可以通过:help topic<Tab>在Vim中轻松找到帮助主题。在这种情况下,:help modeline<Tab>会给你一些主题来解释这个功能以及如何控制它。

答案 1 :(得分:13)

您可以使用

关闭模式行处理
:set nomodeline

有关详细信息,请参阅:help modeline

答案 2 :(得分:1)

:help auto-setting下,您会找到以下段落:

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:").

所以,你的〜/ .vimrc可能有一个set nomodeline

行阅读vi: bad line尝试设置无法设置的选项badline,因此错误。

编辑:正如 jamessan&#39; S 答案(+1)所指出的,modeline选项是通过设置nocompatible设置的仅存在~/.vimrc