9

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

1 Answers1

16

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

autocmd BufNewFile,BufRead *.v,*.vs set syntax=verilog
sidyll
  • 57,726
  • 14
  • 108
  • 151
  • 2
    The "correct" place to put these is in `~/.vim/filetype.vim`; see `:help new-filetype`. (`~/.vimrc` mostly works, too.) – Ingo Karkat Jun 21 '17 at 08:46
  • 1
    There are the two lines of though...for me personally it makes more sense to keep these simple configuration settings in _.vimrc_. – sidyll Jun 21 '17 at 13:22
  • 1
    @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. – Pluto Sep 10 '19 at 00:39
  • `autocmd BufNewFile,BufRead *.v,*.sv,*.vs set syntax=verilog` (same, but including *.sv) just in case your setup doesn't recognize .sv already – mza Feb 17 '21 at 17:14
  • @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. – Steak Overflow Jul 28 '21 at 08:35
  • @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 :-) – Ingo Karkat Jul 28 '21 at 13:48