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.
just as it does by default with matching braces, brackets, parentheses, etc. To use it, put the cursor on a begin or end while in command mode and press % -- it will jump to the matching end / begin . Press % again to jump back to where you started from.
The matchit.vim script allows you to configure % to match more than just. single characters. You can match words and even regular expressions. Also, matching treats strings and comments (as recognized by the. syntax highlighting mechanism) intelligently.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With