Reputation: 674
Is there a way to make same syntax highlighting for different file extensions?
e.g: Same highlighting for
foo.c and foo.my_c_extension
Upvotes: 12
Views: 2854
Reputation: 16184
If you don't want the filetype to be the same, (maybe that has some unwanted side effects), and just want to set the syntax, you can use the following:
autocmd BufRead,BufNewFile *.my_c_extension set syntax=c
Upvotes: 1
Reputation: 270607
Vim will set the syntax highlighting based on a buffer's filetype
. You may set the filetype
via autocmd
to match multiple file extensions.
For example, when a file is loaded or created in a buffer having the .c
or .my_c_extension
extensions, the filetype
will be set to c
:
" In .vimrc, for example:
autocmd BufRead,BufNewFile *.c,*.my_c_extension set filetype=c
See :help filetype
and :help autocmd
for more information.
According to the filetype
help, you may create ~/.vim/ftdetect/file_extension.vim
which contains the autocmd
. That will be loaded after other rules, allowing you to override settings previously made by Vim or plugins. This may be preferable to setting it in your .vimrc
.
" File: ~/.vim/ftdetect/my_c_extension.vim
autocmd BufRead,BufNewFile *.my_c_extension set filetype=c
Upvotes: 12