vim uses a runtime script (such as /usr/share/vim/vim73/filetype.vim
) which checks the filename, matches it in this case as
" Mercurial config (looks like generic config file) au BufNewFile,BufRead *.hgrc,*hgrc setf cfg
The script is documented here: Vim documentation: filetype
You can customize your environment using similar commands (in fact the documentation recommends that you do this rather than modify the installed filetype.vim
). vim's documentation refers to this as an "autocommand", and its documentation is the best place to start reading about the feature: Vim documentation: autocmd