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

13,953

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

autocmd BufNewFile,BufRead *.v,*.vs set syntax=verilog
Share:
13,953
TheSprintingEngineer
Author by

TheSprintingEngineer

Updated on June 09, 2022

Comments

  • TheSprintingEngineer
    TheSprintingEngineer almost 2 years

    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

  • Ingo Karkat
    Ingo Karkat almost 7 years
    The "correct" place to put these is in ~/.vim/filetype.vim; see :help new-filetype. (~/.vimrc mostly works, too.)
  • sidyll
    sidyll almost 7 years
    There are the two lines of though...for me personally it makes more sense to keep these simple configuration settings in .vimrc.
  • Pluto
    Pluto over 4 years
    @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.
  • mza
    mza about 3 years
    autocmd BufNewFile,BufRead *.v,*.sv,*.vs set syntax=verilog (same, but including *.sv) just in case your setup doesn't recognize .sv already
  • SteakOverflow
    SteakOverflow over 2 years
    @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.
  • Ingo Karkat
    Ingo Karkat over 2 years
    @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 :-)