2

vim何もロードせずに開きました:

vim -V -u NONE

そして、1行入力しました:

<?xml?>

実行後:

:unlet did_load_filetypes
:filetype on

現在のバッファのファイル タイプを確認します。

:set ft?

印刷しますfiletype=


入力すると

:unlet did_load_filetypes
:filetype detect

その後、:set ft?印刷されますfiletype=xml


vimドキュメントで:

Detail: The ":filetype on" command will load one of these files:                                    
                Amiga       $VIMRUNTIME/filetype.vim                                                
                Mac         $VIMRUNTIME:filetype.vim                                                
                MS-DOS      $VIMRUNTIME\filetype.vim                                                
                RiscOS      Vim:Filetype                                                            
                Unix        $VIMRUNTIME/filetype.vim                                                
                VMS         $VIMRUNTIME/filetype.vim                                                
        This file is a Vim script that defines autocommands for the                                 
        BufNewFile and BufRead events.  If the file type is not found by the                        
        name, the file $VIMRUNTIME/scripts.vim is used to detect it from the                        
        contents of the file.   

:filetype onとの違いは何:filetype detectですか?
ご協力いただきありがとうございます。

4

2 に答える 2

4

マニュアルから:

To detect the file type again:
    :filetype detect
Use this if you started with an empty file and typed text that makes it
possible to detect the file type.
于 2012-06-01T04:26:35.110 に答える
1

$VIMRUNTIME/filetype.vimBufNewFileおよびイベントの自動コマンドのみを定義しBufReadます。

コマンドを実行した後、:filetype onどのイベントもトリガーされないため、何も起こりません。イベントをトリガーするには、 で保存し、 で再度開き:w filenameます:e!

またはイベント:filetype detectをトリガーするコードを実行すると思います。BufNewFileBufRead

于 2012-06-01T04:24:44.127 に答える