2011-12-20 10 views
8

私は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:で始まっていますが、これを修正する理由または解決方法がわかりません。

答えて

9

vi: bad line行は、Vimがエラーメッセージに記載されているようにmodelineと認識する形式です。 Modelinesでは、ファイル内のオプションを設定できます。

~/.vimrcがないときにトリガーされない理由は、Vim固有の機能であるため、Vimはデフォルトでモードラインを有効にするように'nocompatible'を設定する必要があるからです。しかし、~/.vimrcの存在は、Vimがvi互換モードからnocompatibleに切り替えるのには十分です。その結果、'modeline'オプションも設定されます。

将来的には、:help topic<Tab>でVimのヘルプトピックを簡単に見つけることができます。この場合、:help modeline<Tab>には、この機能の説明とコントロール方法について説明するためのトピックがいくつかあります。

+0

ありがとうございます。私はこれが何が起こっているのか、なぜ(なぜvimrcの存在)の両方が説明されているので、これを受け入れられた答えとしてマークします。 – Danosaure

+0

だから、vimは 'modelines'(すなわちvim設定)として最後の' n'行を理解していますので、このエラーを避けるためにコードの最後の 'n'行を空行または実際の' vim modelines'にしてください。 – shahjapan

10

あなたはより多くの情報を参照してください:help modeline

:set nomodeline 

でモードラインの処理をオフにできます。あなたはこの段落見つける:help auto-settingの下

1

:だから

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を持っています。

設定することができないオプションbadline、したがって誤差を設定しようとvi: bad lineライン読取。

EDITjamessan'Sの回答(1)で指摘したように、modelineオプションは~/.vimrcの単なる存在によってnocompatibleの設定により設定されています。

+0

ありがとうございます。奇妙なことは、私の行が1000行以上で696行(それは/ etc/groupのようにファイルのように大きくなっています)だということです。しかし、それは私の問題を解決します。 – Danosaure

関連する問題