`vi`はどのように設定ファイルの形式を知っていますか?

`vi`はどのように設定ファイルの形式を知っていますか?

で設定ファイルを編集すると、ファイルの構文がわかっているviようです。vi

例えば、viマーカーはキーであるか値であるかに応じて、何らかの方法で色が付けられる。さらに、viどの値が有効なキーであるかがわかります。

どうすればいいですか?

編集:Ubuntu Server 12.04 Precise Pangolin(LTS)を実行していることを追加します。

ベストアンサー1

vim(実際に今日のほとんどのシステムではviシンボリックリンクvim)処理可能なさまざまな言語のカラースキームを定義するために構文ファイルを使用します。使用しているオペレーティングシステムを指定していませんが、私のLMDEシステムでは/usr/share/vim/vim74/syntax/

を使用してファイルを開くと、vimまずそのファイルがどのタイプであるかを調べようとします。説明したように公式文書:

ファイルをロードした後、Vimは以下のように関連する構文ファイルを見つけます。

Loading the file triggers the BufReadPost autocommands.
|
+-  If there is a match with one of the autocommands from |synload-3|
|   (known file types) or |synload-4| (user's file types), the 'filetype'
|   option is set to the file type.
|
+-  The autocommand at |synload-5| is triggered.  If the file type was not
|   found yet, then scripts.vim is searched for in 'runtimepath'.  This
|   should always load $VIMRUNTIME/scripts.vim, which does the following.
|   |

|   +-  Source the user's optional file, from the *myscriptsfile*
|   |   variable.  This is for backwards compatibility with Vim 5.x only.
|   |
|   +-  If the file type is still unknown, check the contents of the file,
|       again with checks like "getline(1) =~ pattern" as to whether the
|       file type can be recognized, and set 'filetype'.
|
+-  When the file type was determined and 'filetype' was set, this
|   triggers the FileType autocommand |synload-6| above.  It sets
|   'syntax' to the determined file type.
|
+-  When the 'syntax' option was set above, this triggers an autocommand
|   from |synload-1| (and |synload-2|).  This find the main syntax file in
|   'runtimepath', with this command:
|       runtime! syntax/<name>.vim
|
+-  Any other user installed FileType or Syntax autocommands are
triggered.  This can be used to change the highlighting for a specific
syntax.

したがって、基本的にvimいくつかのトリックを使用してファイル形式を解析して推測し、適切な構文ファイルをロードします。構成ファイルの構文を定義するファイルは/usr/share/vim/vim74/syntax/config.vim

おすすめ記事