VIM highlight matching begin/end

11.6k Views Asked by At

I'm trying to find a plugin that will highlight the matching begin/end statements with Verilog. VIM has it working with curly braces /brackets but it does not work with its begin/end. I want VIM to highlight the correct begin to the correct end.

4

There are 4 best solutions below

3
On BEST ANSWER

In my opinion, your best bet is using matchit. This script is part of vim runtime and can easily be loaded by adding the following line to your .vimrc:

runtime macros/matchit.vim

The standard Verilog filetype plugin already includes the matchit configuration you require:

" Let the matchit plugin know what items can be matched.
if exists("loaded_matchit")
  let b:match_ignorecase=0
  let b:match_words=
    \ '\<begin\>:\<end\>,' .
    \ '\<case\>\|\<casex\>\|\<casez\>:\<endcase\>,' .
    \ '\<module\>:\<endmodule\>,' .
    \ '\<if\>:\<else\>,' .
    \ '\<function\>:\<endfunction\>,' .
    \ '`ifdef\>:`else\>:`endif\>,' .
    \ '\<task\>:\<endtask\>,' .
    \ '\<specify\>:\<endspecify\>'
endif

This way you can match the begin/end using % key, as you probably already do for parentheses and such.

This is not exactly what you were looking for, in the sense that although it allows you to find the matching end of a begin it does not highlight it for you. I did some research and apparently there's a code snippet around for that; and there's someone who already transformed that code into a plugin, which is named hl_matchit. Don't forget to check this plugin's help page:

:help hl_matchit.txt

Please note that the Verilog filetype plugin included in vim installation does not support the ifndef and elsif clauses introduced in Verilog 2001. If you require this then I suggest that you also install the verilog_systemverilog.vim plugin already mentioned before, but use the fork I am improving which includes the afore mentioned updates, as well as other fixes/improvements.

0
On

I'm not aware of any plugin that does this, but you can probably derive that functionality from the related html_MatchTag plugin, which implements this for HTML tags, by adapting to the Verilog filetype and replacing the corresponding regular expressions.

2
On

Answering to your question. Have a look on a syntax file systemverilog.vim 25 line:

syntax region svCase matchgroup=svConditional start="\<case\|casex\|casez\>" end="\<endcase\>" contains=ALL
  • syntax is a vim command (:he syntax for more explanation)
  • region keyword for region
  • svCase just name
  • matchgroup - The syntax group to use for the following start or end pattern matches only.
  • start and end - regexps for marking start and end syntax region
  • contains=ALL means then all other groups will be accepted inside the region.

Hope that's you looking for.

0
On

Install the system verilog plugin: https://github.com/vhda/verilog_systemverilog.vim

Install matchit :he matchit and you are good to go!