Add syntax highlighting to certain file extensions for VIM or GVIM by default
Asked Answered
A

1

10

In my Linux machine files with the .sv extension opens up by default with the verilog syntax highlighting scheme, however extension with .vor .vs don't. I have to manually in gvim do a :set syntax=verilog every time I open one of these files.

How do I make those file extensions .v or .vs open up in a verilog syntax highlighting by default ?

Thanks

Arvillaarvin answered 18/6, 2017 at 14:35 Comment(0)
T
18

Add an auto-command to your .vimrc to do that for you:

autocmd BufNewFile,BufRead *.v,*.vs set syntax=verilog
Tartrate answered 18/6, 2017 at 15:16 Comment(6)
The "correct" place to put these is in ~/.vim/filetype.vim; see :help new-filetype. (~/.vimrc mostly works, too.)Barbarism
There are the two lines of though...for me personally it makes more sense to keep these simple configuration settings in .vimrc.Tartrate
@IngoKarkat In my case, setting the filetype via filetype.vim didn't work because I needed to override a filetype that was already detected correctly but didn't provide syntax highlighting.Spirograph
autocmd BufNewFile,BufRead *.v,*.sv,*.vs set syntax=verilog (same, but including *.sv) just in case your setup doesn't recognize .sv alreadyQuadrangular
@IngoKarkat From the :help new-filetype => "In any way, it's better not to modify the $VIMRUNTIME/filetype.vim file. It will be overwritten when installing a new version of Vim." They then suggest to put a file with the autocommand in a folder called ftdetect. Perhaps they updated the help since you commented.Dodge
@SteakOverflow: The help mentions four ways. Your is referred to as option A, while mine is option C. Both are fine; one is fine-granular, the other keeps everything in one place. I actually use both approaches in parallel :-)Barbarism

© 2022 - 2024 — McMap. All rights reserved.