VIM E518:未知的选项:
我有UNIX系统上的文本文件。下面的文本文件的内容创建问题:VIM E518:未知的选项:
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:
创建的错误开始,但我不明白为什么或如何解决这个问题。
vi: bad line
行的格式为Vim将其识别为modeline,如错误消息中所述。 Modelines允许在文件中设置选项。
当你没有~/.vimrc
时它没有被触发的原因是因为Vim要求你有'nocompatible'
设置默认启用模式行,因为它是一个Vim特定的功能。的~/.vimrc
的存在是足够的Vim从VI-兼容模式切换到nocompatible,不过,这将导致在'modeline'
选项也被设置。
对于未来的参考,你可以很容易地找到通过:help topic<Tab>
帮助Vim的话题。在这种情况下,:help modeline<Tab>
会给你几个主题来看看解释这个功能以及如何控制它。
您可以关闭模式行处理与
:set nomodeline
更多信息请参见:help modeline
。
在: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
行尝试设置选项bad
和line
不能设置,因此错误。
EDIT:由于jamessan'S答案(1)所指出的,modeline
选项是通过由nocompatible的~/.vimrc
仅仅存在的设置设定。
非常感谢您的解释。奇怪的是,我的行只是一行1000行中的696行(它是大/ etc/group文件)。但它解决了我的问题。 – Danosaure 2011-12-21 15:49:00
谢谢你。我将这个标记为接受的答案,因为它解释了它发生了什么以及为什么(存在vimrc)。 – Danosaure 2011-12-21 15:52:46
所以Vim理解最后'N'行作为'modelines'(即VIM设置),所以它理想的是一个应该保持最后'他的代码或者为空,线或实际'VIM modelines' N'线来避免这种错误。 – shahjapan 2012-03-30 04:56:55