2012-06-01 3 views
1

Я открыл vim без загрузки ничего:Почему `filetype on` не определяет тип файла в vim?

vim -V -u NONE 

И набрали одну строку:

<?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?
Спасибо за помощь.

ответ

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 определяет только автокоманды для BufNewFile и BufRead событий.

После запуска команды :filetype on ни одно из событий не запускается, поэтому ничего не произошло. Чтобы trigge событие, вы можете сохранить его с :w filename, и открыть его с :e!

Я думаю, :filetype detect пробегов некоторый код для запуска BufNewFile или BufRead события.