Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM highlight matching begin/end

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.

like image 589
GoChanGo Avatar asked Dec 16 '14 05:12

GoChanGo


People also ask

How to match begin end in vim?

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.

What is Matchit Vim?

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.


1 Answers

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.

like image 199
Vitor Avatar answered Oct 01 '22 07:10

Vitor