Last Updated: June 12, 2023
·
10.32K
· parvizp

Vim and SystemVerilog

Want to use Vim to edit SystemVerilog? Unfortunatly, Vim doesn't provide much SystemVerilog support out of the box. I think the most basic features needed to be productive are syntax highlighting and ctags support.

Syntax Highlighting

If you use Vundle, add the bundle to your vimrc and BundleInstall:

Bundle 'nachumk/systemverilog.vim'

ctags

I find using ctags to be very helpful, particularly with a large package like UVM. There are some contributions found here: http://www.verificationguild.com/modules.php?name=Forums&file=viewtopic&t=1621

Jus add the following regular expressions to your ~/.ctags

--langdef=systemverilog
--langmap=systemverilog:.sv.svh.svi
--regex-systemverilog=/^[ \t]*(virtual)?[ \t]*class[ \t]*([a-zA-Z_0-9]+)/\2/c,class/

--regex-systemverilog=/^[ \t]*(virtual)?[ \t]*task[ \t]*.*::([a-zA-Z_0-9]+)[\t]*[(;]/\2/t,task/
--regex-systemverilog=/^[ \t]*(virtual)?[ \t]*function[ \t]*.*::([a-zA-Z_0-9]+)[ \t]*[(;]/\2/f,function/

--regex-systemverilog=/^[ \t]*module[ \t]*([a-zA-Z_0-9]+)/\1/m,module/
--regex-systemverilog=/^[ \t]*program[ \t]*([a-zA-Z_0-9]+)/\1/p,program/
--regex-systemverilog=/^[ \t]*interface[ \t]*([a-zA-Z_0-9]+)/\1/i,interface/
--regex-systemverilog=/^[ \t]*typedef[ \t]+.*[ \t]+([a-zA-Z_0-9]+)[ \t]*;/\1/e,typedef/
--regex-systemverilog=/^[ \t]*`define[ \t]*([a-zA-Z_0-9]+)/`\1/d,define/

--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*shortint[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*int[ \t]*(unsigned)?[ \t]*([a-zA-Z_0-9]+).*/`\6/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*longint[ \t]*(unsigned)?[ \t]*([a-zA-Z_0-9]+).*/`\6/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*byte[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*bit[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*logic[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*reg[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*integer[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*(rand)?[ \t]*time[ \t]*([a-zA-Z_0-9]+).*/`\5/v,variable/

--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*real[ \t]*([a-zA-Z_0-9]+).*/`\4/v,variable
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*shortreal[ \t]*([a-zA-Z_0-9]+).*/`\4/v,variable/

--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*chandle[ \t]*([a-zA-Z_0-9]+).*/`\4/v,variable/
--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*string[ \t]*([a-zA-Z_0-9]+).*/`\4/v,variable/

--regex-systemverilog=/^[ \t]*(static)?[ \t]*(local)?[ \t]*(private)?[ \t]*event[ \t]*([a-zA-Z_0-9]+).*/`\4/v,variable/

--regex-systemverilog=/^[ \t]*`SVT_REPLACEABLE_DEFINE\([ \t]*([a-zA-Z_0-9]+),.*\)/`\1/d,define/

--systemverilog-kinds=+ctfmpied

--langdef=altsystemverilog
--regex-altsystemverilog=/^[ \t]*(extern)?[ \t]*(virtual)?[ \t]*(protected)?[ \t]*class[ \t]*([a-zA-Z_0-9]+)/\4/c,class/
--regex-altsystemverilog=/^[ \t]*(extern)?[ \t]*(virtual)?[ \t]*(protected)?[ \t]*task[ \t]*.*[ \t]+([a-zA-Z_0-9]+)[\t]*[(;]/\4/t,task
--regex-altsystemverilog=/^[ \t]*(extern)?[ \t]*(virtual)?[ \t]*(protected)?[ \t]*function[ \t]*.*[ \t]+([a-zA-Z_0-9]+)[ \t]*[(;]/\4/f,function/
--regex-altsystemverilog=/^[ \t]*(virtual)?[ \t]*task[ \t]*.*[ \t]+([a-zA-Z_0-9]+)[\t]*[(;]/\2/t,task/
--regex-altsystemverilog=/^[ \t]*(virtual)?[ \t]*function[ \t]*.*[ \t]+([a-zA-Z_0-9]+)[ \t]*[(;]/\2/f,function/

You need to do a one-time pass of your UVM library:

cd my_UVM_path
ctags --languages=systemverilog -R .
mv tags ~/.vim/tags/UVM

To use the ctags for your UVM project, first add the following to your ~/.vimrc:

set tags=./tags;
set tags+=~/.vim/tags/UVM

Then for each project:

cd my_project
ctags -R .

3 Responses
Add your response

--regex-systemverilog=/^[ \t](static)?[ \t](local)?[ \t](private)?[ \t]real[ \t]([a-zA-Z_0-9]+)./`\4/v,variable

Above line last character "/" is missing hence creating error...

over 1 year ago ·

Does not process functions/tasks that return a type, e.g function myType myFunction()....

over 1 year ago ·

I am getting below warnings.
ctags: Warning: unknown regex flag: 'v'
ctags: Warning: unknown regex flag: 't'

how to fix these?

10 months ago ·