2012-06-01 35 views
1

我打開vim無需加載任何東西:爲什麼'filetype on`在vim中沒有檢測到文件類型?

vim -V -u NONE 

和類型一行:

:unlet did_load_filetypes 
:filetype on 

我檢查當前緩衝區的文件類型:

<?xml?> 

運行後

: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之間的區別是什麼?
感謝您的幫助。

回答

3

從手冊:

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. 
0

$VIMRUNTIME/filetype.vim只定義了BufNewFileBufRead事件的自動命令。

運行:filetype on命令後,沒有任何事件被觸發,所以沒有發生任何事情。爲了trigge的情況下,你可以用:w filename保存,並與:e!

我想,:filetype detect運行一些代碼,重新打開它觸發BufNewFileBufRead事件。

相關問題