how to make file extensions to syntax highlighting in vim?

独自空忆成欢 提交于 2019-12-12 05:34:27

问题


I have *.q files ( that are very similar to other SQL ) and I want to make vim syntax highlight it in the same way as SQL.


回答1:


Include it in the ~/.vim/filetype.vim, as described at Vim FAQ 26.8:

" my filetype file
if exists("did_load_filetypes")
    finish
endif
augroup filetypedetect
    au! BufRead,BufNewFile *.x       setfiletype c
augroup END

For this case it would be changed to something like this:

    au! BufRead,BufNewFile *.q       setfiletype sql

Check :help new-filetype for additional details.




回答2:


create a ~/.vim/ftdetect directory if not existing.
create a ~/.vim/ftdetect/<new-file-type-extention>.vim with content:

au BufRead,BufNewFile *.<new-file-type-extention> set filetype=<existing-file-type-extention>


来源:https://stackoverflow.com/questions/30979880/how-to-make-file-extensions-to-syntax-highlighting-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!