vim
(na maioria dos sistemas atualmente, vi
é realmente um link simbólico para vim
) usa arquivos de sintaxe para definir os esquemas de coloração para os vários idiomas com os quais ele pode lidar. Você não especificou qual sistema operacional você usa, mas no meu sistema LMDE, estes são encontrados em /usr/share/vim/vim74/syntax/
.
Quando você abre um arquivo usando vim
, ele primeiro tenta descobrir qual tipo de arquivo é. Conforme explicado na documentação oficial :
Upon loading a file, Vim finds the relevant syntax file as follows:
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.
Portanto, basicamente, vim
usa alguns truques para analisar e adivinhar o tipo de arquivo e, em seguida, carregará o arquivo de sintaxe apropriado. O arquivo que define a sintaxe dos arquivos de configuração é /usr/share/vim/vim74/syntax/config.vim
.