为什么`filetype on`不';无法检测vim中的文件类型?

为什么`filetype on`不';无法检测vim中的文件类型?,vim,ubuntu-12.04,Vim,Ubuntu 12.04,我打开了vim,但没有加载任何内容: vim -V -u NONE 并键入一行: <?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:

我打开了vim,但没有加载任何内容:

vim -V -u NONE
并键入一行:

<?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
之间有什么区别?

感谢您的帮助。

$VIMRUNTIME/filetype.vim
仅为
BufNewFile
BufRead
事件定义自动命令

在运行
:filetype on
命令后,没有触发任何事件,因此没有发生任何事情。要触发事件,您可以使用
:w filename
保存它,然后使用
:e!重新打开它

我猜,
:filetype detect
运行一些代码来触发
BufNewFile
BufRead
事件。

来自手册:

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