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
Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open . vimrc file, change the text “syntax on” to “syntax off” and save the file.
Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.
You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With