systemverilog.vim

3,741 views
Skip to first unread message

analogsix

unread,
Nov 5, 2012, 8:29:54 PM11/5/12
to vim...@googlegroups.com
have a systemverilog.vim file that I source from my .vimrc through the following command:

syntax on
au BufEnter *.sv, *.svh source ~/.vim/syntax/systemverilog.vim

When opening mulitple .sv files through the command-line for editing, VIM does not syntax highlight the files.

Only opening individual files works.

What could be wrong?

Ben Fritz

unread,
Nov 5, 2012, 9:13:48 PM11/5/12
to vim...@googlegroups.com
One thing that's wrong is you're not supposed to have a space between *.sv and *.svh.

Potentially there could also be a problem in your systemverilog.vim file. Where did you get it? Or if you made it yourself, what is in it?

analogsix

unread,
Nov 6, 2012, 12:07:17 AM11/6/12
to vim...@googlegroups.com
Thanks for the tip. I'll try it.
I got the syntax file from a co-worker. It's also somewhere on VIM sourceforge
---
" Vim syntax file
" Language: SystemVerilog
"
" Last Update: Wed Jun 14 15:56:00 BST 2006
" Built on verilog.vim from vim63

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

" Set the local value of the 'iskeyword' option
if version >= 600
setlocal iskeyword=@,48-57,_,192-255
else
set iskeyword=@,48-57,_,192-255
endif

" Taken from the SystemVerilog 3.1a Annex B:
syn keyword systemverilogStatement alias always always_comb always_ff always_latch
syn keyword systemverilogStatement and assert assign assume automatic before begin
syn keyword systemverilogStatement bind bins binsof bit break buf bufif0 bufif1
syn keyword systemverilogStatement byte case casex casez cell chandle class clocking
syn keyword systemverilogStatement cmos config const constraint context continue cover
syn keyword systemverilogStatement covergroup coverpoint cross deassign default
syn keyword systemverilogStatement defparam design disable dist do edge else end
syn keyword systemverilogStatement endcase endclass endclocking endconfig endfunction
syn keyword systemverilogStatement endgenerate endgroup endinterface endmodule
syn keyword systemverilogStatement endpackage endprimitive endprogram endproperty
syn keyword systemverilogStatement endspecify endsequence endtable endtask enum event
syn keyword systemverilogStatement expect export extends extern final first_match for
syn keyword systemverilogStatement force foreach forever fork forkjoin function generate
syn keyword systemverilogStatement genvar highz0 highz1 if iff ifnone ignore_bins
syn keyword systemverilogStatement illegal_bins import incdir include initial inout
syn keyword systemverilogStatement input inside instance int integer interface intersect
syn keyword systemverilogStatement join join_any join_none large liblist library local
syn keyword systemverilogStatement localparam logic longint macromodule matches medium
syn keyword systemverilogStatement modport module nand negedge new nmos nor
syn keyword systemverilogStatement noshowcancelled not notif0 notif1 null or output
syn keyword systemverilogStatement package packed parameter pmos posedge primitive
syn keyword systemverilogStatement priority program property protected pull0 pull1
syn keyword systemverilogStatement pulldown pullup pulsestyle_onevent pulsestyle_ondetect
syn keyword systemverilogStatement pure rand randc randcase randsequence rcmos
syn keyword systemverilogStatement real realtime ref reg release repeat return
syn keyword systemverilogStatement rnmos rpmos rtran rtranif0 rtranif1 scalared sequence
syn keyword systemverilogStatement shortint shortreal showcancelled signed small solve
syn keyword systemverilogStatement specify specparam static string strong0 strong1 struct
syn keyword systemverilogStatement super supply0 supply1 table tagged task this
syn keyword systemverilogStatement throughout time timeprecision timeunit tran
syn keyword systemverilogStatement tranif0 tranif1 tri tri0 tri1 triand trior trireg type
syn keyword systemverilogStatement typedef union unique unsigned use var vectored virtual
syn keyword systemverilogStatement void wait wait_order wand weak0 weak1
syn keyword systemverilogStatement while wildcard wire with within wor xnor xor

" LRM 3.7 String methods:
syn keyword systemverilogStatement len getc putc toupper tolower compare
syn keyword systemverilogStatement icompare substr
syn keyword systemverilogStatement itoa hextoa octtoa bintoa realtoa
syn keyword systemverilogStatement atoi atohex atooct atobin atoreal
" LRM 3.8 events:
syn keyword systemverilogStatement triggered
" LRM 3.10 methods for enumerated types:
syn keyword systemverilogStatement first last next prev num name
" LRM 4.6 Dynamic Arrays:
syn keyword systemverilogStatement delete
" LRM 4.10 Associative Array methods:
syn keyword systemverilogStatement num exists
" LRM 4.15.1 Array locator methods:
syn keyword systemverilogStatement find find_index find_first find_first_index
syn keyword systemverilogStatement find_last find_last_index min max unique unique_index
" LRM 4.15.2 Array ordering methods:
syn keyword systemverilogStatement reverse sort rsort shuffle
" LRM 4.15.3 Array reduction methods:
syn keyword systemverilogStatement sum product
" LRM 4.15.4 Array iterator query:
syn keyword systemverilogStatement index
"" LRM 7.10.1 Builtin package:
syn keyword systemverilogStatement std
" LRM Annex C standard library
syn keyword systemverilogStatement get put try_get try_put peek try_peek
syn keyword systemverilogStatement status kill self await suspend resume
" LRM Annex D List methods
syn keyword systemverilogStatement next prev eq neq data
syn keyword systemverilogStatement size empty push_front push_back
syn keyword systemverilogStatement front back pop_front pop_back
syn keyword systemverilogStatement start finish insert insert_range
syn keyword systemverilogStatement erase erase_range set swap clear purge

" New time specification:
" #1step or #1ps
syn match systemverilogNumber "\<[0-9_]\+\([munpf]\|\)s\>"
syn match systemverilogNumber "\<[0-9_]\+step\>"

" Original systemverilog syntax below here

syn keyword systemverilogTodo contained TODO

syn match systemverilogOperator "[&|~><!)(*#%@+/=?:;}{,.\^\-\[\]]"

syn region systemverilogComment start="/\*" end="\*/" contains=systemverilogTodo
syn match systemverilogComment "//.*" contains=systemverilogTodo

"syn match systemverilogGlobal "`[a-zA-Z0-9_]\+\>"
syn match systemverilogGlobal "`celldefine"
syn match systemverilogGlobal "`default_nettype"
syn match systemverilogGlobal "`define"
syn match systemverilogGlobal "`else"
syn match systemverilogGlobal "`elsif"
syn match systemverilogGlobal "`endcelldefine"
syn match systemverilogGlobal "`endif"
syn match systemverilogGlobal "`ifdef"
syn match systemverilogGlobal "`ifndef"
syn match systemverilogGlobal "`include"
syn match systemverilogGlobal "`line"
syn match systemverilogGlobal "`nounconnected_drive"
syn match systemverilogGlobal "`resetall"
syn match systemverilogGlobal "`timescale"
syn match systemverilogGlobal "`unconnected_drive"
syn match systemverilogGlobal "`undef"
syn match systemverilogGlobal "$[a-zA-Z0-9_]\+\>"

syn match systemverilogConstant "\<[A-Z][A-Z0-9_]\+\>"

syn match systemverilogNumber "\(\<\d\+\|\)'[bB]\s*[0-1_xXzZ?]\+\>"
syn match systemverilogNumber "\(\<\d\+\|\)'[oO]\s*[0-7_xXzZ?]\+\>"
syn match systemverilogNumber "\(\<\d\+\|\)'[dD]\s*[0-9_xXzZ?]\+\>"
syn match systemverilogNumber "\(\<\d\+\|\)'[hH]\s*[0-9a-fA-F_xXzZ?]\+\>"
syn match systemverilogNumber "\<[+-]\=[0-9_]\+\(\.[0-9_]*\|\)\(e[0-9_]*\|\)\>"

syn region systemverilogString start=+"+ skip=+\\"+ end=+"+ contains=systemverilogEscape
syn match systemverilogEscape +\\[nt"\\]+ contained
syn match systemverilogEscape "\\\o\o\=\o\=" contained

" Directives
syn match systemverilogDirective "//\s*synopsys\>.*$"
syn region systemverilogDirective start="/\*\s*synopsys\>" end="\*/"
syn region systemverilogDirective start="//\s*synopsys dc_script_begin\>" end="//\s*synopsys dc_script_end\>"

syn match systemverilogDirective "//\s*\$s\>.*$"
syn region systemverilogDirective start="/\*\s*\$s\>" end="\*/"
syn region systemverilogDirective start="//\s*\$s dc_script_begin\>" end="//\s*\$s dc_script_end\>"

"Modify the following as needed. The trade-off is performance versus
"functionality.
syn sync lines=80

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_systemverilog_syn_inits")
if version < 508
let did_systemverilog_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif

" The default highlighting.
HiLink systemverilogCharacter Character
HiLink systemverilogConditional Conditional
HiLink systemverilogRepeat Repeat
HiLink systemverilogString String
HiLink systemverilogTodo Todo
HiLink systemverilogComment Comment
HiLink systemverilogConstant Constant
HiLink systemverilogLabel Label
HiLink systemverilogNumber Number
HiLink systemverilogOperator Special
HiLink systemverilogStatement Statement
HiLink systemverilogGlobal Define
HiLink systemverilogDirective SpecialComment
HiLink systemverilogEscape Special

delcommand HiLink
endif

let b:current_syntax = "systemverilog"

" vim: ts=2

analogsix

unread,
Nov 6, 2012, 11:43:56 AM11/6/12
to vim...@googlegroups.com
turns out that the file list already had no spaces
the problem is ongoing.

Ben Fritz

unread,
Nov 6, 2012, 1:53:10 PM11/6/12
to vim...@googlegroups.com
On Monday, November 5, 2012 7:29:54 PM UTC-6, analogsix wrote:
> have a systemverilog.vim file that I source from my .vimrc through the following command:
>
> syntax on
> au BufEnter *.sv,*.svh source ~/.vim/syntax/systemverilog.vim
>
> When opening mulitple .sv files through the command-line for editing, VIM does not syntax highlight the files.
>

What is the exact command you give to open multiple files from the command-line? How do you switch between them, if you do not open them all in split windows or the like?

> Only opening individual files works.
>
> What could be wrong?

What is the result of the following command in the non-highlighted files?

:verbose set filetype? syntax?

What OS are you on? What version of Vim are you using (and what feature set, TINY/NORMAL/BIG/HUGE)?

Gary Johnson

unread,
Nov 6, 2012, 1:54:05 PM11/6/12
to vim...@googlegroups.com
A couple of things.

First off, if you're going to use syntax highlighting, you should
really do it the way it's designed to work and not go off and do it
somehow differently. Rather than put an autocommand in your
~/.vimrc, just use

filetype on

and if you discover that Vim does not detect the systemverilog
filetype, then create a file named ~/.vim/ftdetect/systemverilog.vim
and put this in it:

au BufRead,BufNewFile *.sv,*.svh set filetype=systemverilog

Secondly, a BufEnter autocommand is triggered only when you enter a
buffer, not when you just display it. For example, execute this
command,

vim -Nu NONE --cmd 'au BufEnter * echomsg "hello" expand("%")' -O file1 file2 file3

then execute

:messages

You will see this:

"file1" 0L, 0C
hello file1
"file2" 0L, 0C
"file3" 0L, 0C
hello file1

If you then type Ctrl-W Ctrl-W twice and execute ":messages" again
you will see this:

"file1" 0L, 0C
hello file1
"file2" 0L, 0C
"file3" 0L, 0C
hello file1
hello file2
hello file3

Regards,
Gary

analogsix

unread,
Nov 6, 2012, 8:05:33 PM11/6/12
to vim...@googlegroups.com
thanks for assisting. I'm new to Linux command-line and VIM.
I'm using a Linux OS at work.

I type in vim -O3 file1.sv file2.sv file3.svh file4.sv file5.sv

I get 3 windows and 5 buffers. The active window/buffer IS syntax highlighted. The inactive ones ARE NOT until I ^Ww through them. This may have something to do with the BufEnter event... so I tried VimEnter instead. In the latter case, none were highlighted.

So I entered :verbose set filetype? syntax?

I see:

filetype=
syntax=
Last set from /usr/share/vim/vim70/syntax.vim

version is HUGE with GTK2 GUI

Guess my syntax files are not getting fired up

My co-worker was the one who originally passed me the systemverilog.vim syntax file. He doesn't have mastery over VIM scripting. I also used a copy of his .vimrc. thanks for bearing with me.

This is why I've been ramping up my VIM learning; I'm also doing it to set up an optimal SystemVerilog code editing environment complete with plugins. My new boss said to me "it's either you learn VIM or Emacs, and I chose VIM even though Emacs is popular with the Verilog-mode." At any rate, learning on VIM has led me down the rabbit hole of reading the majority of Arnold Robbins' Learning Vi and VIM (haven't yet finished scripting and the programming stuff... altho its not very succinctly written), reading different sections of the VimUserManual and Reference, as well as exploring the directory structure of /usr/share/vim/vim70/ directories as well as file contents therein. Hence I created my own ~/.vim directory and mkdired the following sub-directories: syntax/, plugin/, filetype/ (they're all empty except syntax/). But I'm still figuring out VIM's execution sequence of RC files. I know it reads a bunch of stuff in the /usr/share/.. directory but I've been led to believe it LASTLY checks out your $HOME directory for a .vimrc file and somewhere I read someone put their .vimrc in a ~/.vim/ directory. At the very last it checks out .vimrc files in your CURRENT directory, which I'm not having anything to do with now.

I'm trying to master how to set up my directory $HOME structure with respect to VIM. What files go where? On skimming through Gary's response, I see he mentions a bit of that.

Other references I refer to (I plan on getting plugins installed in the near future):
- the general internet
- VIM Wikia
- Vimscripts on Github, from where I found Vundle plugin (plugin for plugin management)
- http://learnvimscriptthehardway.stevelosh.com/
- http://net.tutsplus.com/sessions/vim-essential-plugins/
plug-ins I'm interested in
- Vundle
- NerdTree
- VimShell

Onto replying to Gary...

analogsix

unread,
Nov 6, 2012, 8:08:29 PM11/6/12
to vim...@googlegroups.com
I should clarify I usually launch

vim -O3 ...

from the project directories with all the company *.sv RTL files... not from my $HOME directory. Thanks

Gary Johnson

unread,
Nov 6, 2012, 9:21:04 PM11/6/12
to vim...@googlegroups.com
On 2012-11-06, analogsix wrote:

> At any rate, learning on VIM has led me down the rabbit hole of
> reading the majority of Arnold Robbins' Learning Vi and VIM
> (haven't yet finished scripting and the programming stuff... altho
> its not very succinctly written), reading different sections of
> the VimUserManual and Reference, as well as exploring the
> directory structure of /usr/share/vim/vim70/ directories as well
> as file contents therein.

Vim 7.0 may work very well for you and it may be best to stick with
what everyone else at your workplace is using. I should mention,
though, that the current version of Vim is 7.3.712, so you _may_ be
seeing problems that have been fixed since your version was
released.

> Hence I created my own ~/.vim directory and mkdired the following
> sub-directories: syntax/, plugin/, filetype/ (they're all empty
> except syntax/).

~/.vim/filetype is not a standard Vim directory. You probably want
~/.vim/ftplugin instead.

> But I'm still figuring out VIM's execution sequence of RC files.
> I know it reads a bunch of stuff in the /usr/share/.. directory
> but I've been led to believe it LASTLY checks out your $HOME
> directory for a .vimrc file and somewhere I read someone put their
> .vimrc in a ~/.vim/ directory. At the very last it checks out
> .vimrc files in your CURRENT directory, which I'm not having
> anything to do with now.

Which vimrc files Vim looks for at startup and in what order is
explained here:

:help vimrc

and the whole startup process here:

:help startup

> I'm trying to master how to set up my directory $HOME structure
> with respect to VIM. What files go where? On skimming through
> Gary's response, I see he mentions a bit of that.

I didn't find documentation of Vim's standard directory structure,
but you can see an example in $VIMRUNTIME, for example by executing

:!ls $VIMRUNTIME

Regards,
Gary

Ben Fritz

unread,
Nov 7, 2012, 11:22:01 AM11/7/12
to vim...@googlegroups.com
On Tuesday, November 6, 2012 7:05:33 PM UTC-6, analogsix wrote:
> I type in vim -O3 file1.sv file2.sv file3.svh file4.sv file5.sv
>
> I get 3 windows and 5 buffers. The active window/buffer IS syntax highlighted.
> The inactive ones ARE NOT until I ^Ww through them. This may have something to
> do with the BufEnter event... so I tried VimEnter instead. In the latter case,
> none were highlighted.
>

Because you used BufEnter, this is expected. BufEnter means "when the cursor
enters a buffer". It looks like :help BufEnter may be a little misleading here.

What you want is "when Vim reads a file into memory to create the buffer" and
probably also "when Vim creates a buffer for a new file". For the first, use
BufRead. For the second, BufNewFile. Gary actually suggested this in a prior
message, and it should work as you intend.

However, this is NOT the standard way to apply a filetype and syntax to a
filetype Vim does not yet recognize. See :help new-filetype for the standard
method. I highly recommend you use it.

I have no idea why you tried VimEnter. Granted, this ought to have worked for a
single buffer. However, VimEnter fires once, in the context the first buffer
being edited, after Vim starts up and after initialization. It has nothing to do
with loading buffers.

> So I entered :verbose set filetype? syntax?
>
> I see:
> filetype=
> syntax=
> Last set from /usr/share/vim/vim70/syntax.vim
>
> version is HUGE with GTK2 GUI
>

It doesn't matter for this problem, but your version string should also include
the numeric version of Vim, in my case 7.3.709 for example.

> Guess my syntax files are not getting fired up
>
> My co-worker was the one who originally passed me the systemverilog.vim syntax
> file. He doesn't have mastery over VIM scripting. I also used a copy of his
> .vimrc. thanks for bearing with me.
>
> This is why I've been ramping up my VIM learning; I'm also doing it to set up
> an optimal SystemVerilog code editing environment complete with plugins. My
> new boss said to me "it's either you learn VIM or Emacs, and I chose VIM even
> though Emacs is popular with the Verilog-mode." At any rate, learning on VIM
> has led me down the rabbit hole of reading the majority of Arnold Robbins'
> Learning Vi and VIM (haven't yet finished scripting and the programming
> stuff... altho its not very succinctly written), reading different sections of
> the VimUserManual and Reference, as well as exploring the directory structure
> of /usr/share/vim/vim70/ directories as well as file contents therein. Hence I
> created my own ~/.vim directory and mkdired the following sub-directories:
> syntax/, plugin/, filetype/ (they're all empty except syntax/). But I'm still
> figuring out VIM's execution sequence of RC files. I know it reads a bunch of
> stuff in the /usr/share/.. directory but I've been led to believe it LASTLY
> checks out your $HOME directory for a .vimrc file and somewhere I read someone
> put their .vimrc in a ~/.vim/ directory. At the very last it checks out .vimrc
> files in your CURRENT directory, which I'm not having anything to do with now.
>

Vim does NOT by default read a .vimrc in your current directory. Only your
$HOME directory, a.k.a. ~ directory.

> I'm trying to master how to set up my directory $HOME structure with respect
> to VIM. What files go where? On skimming through Gary's response, I see he
> mentions a bit of that.
>
> Other references I refer to (I plan on getting plugins installed in the near future):
> - the general internet
> - VIM Wikia
> - Vimscripts on Github, from where I found Vundle plugin (plugin for plugin management)
> - http://learnvimscriptthehardway.stevelosh.com/
> - http://net.tutsplus.com/sessions/vim-essential-plugins/
> plug-ins I'm interested in
> - Vundle
> - NerdTree
> - VimShell
> Onto replying to Gary...

I consider these two to be my only "must have" plugins:

1. Gundo (but see also the alternatives): Script page is
http://www.vim.org/scripts/script.php?script_id=3304 , a good writeup with
some alternatives is here: http://vim.wikia.com/wiki/Using_undo_branches
2. Surround: http://www.vim.org/scripts/script.php?script_id=1697

I'm not sure how useful Surround is for Verilog. If you install Surround you
probably also want Repeat: http://www.vim.org/scripts/script.php?script_id=2136.
More recent versions of both are available on the github page linked from each
script page.
Reply all
Reply to author
Forward
0 new messages