Question

I'm now using gvim to write verilog code. When i use the auto indent full text function (command: gg=G), gvim starts to auto indent the full text. However, gvim can recognize "// begin" but can not recognize "// end", which leads to wrong code indents. e.g.(after input command gg=G):

always@(posedge iClk) begin
    some codes.....
    if(condition....) begin
        some codes....
    end
    //if(condition..) begin
        //some commented out codes...
        //end
        if(condition...) begin
            some codes...
        end
    end

Gvim can recognize the begin in //if(condition) begin, and auto indents the next line //some commented out code.... But when comes to //end, gvim falls to recognize and makes wrong code indents to all the codes below the //end.

Could someone tell me how to solve this problem, please?

Was it helpful?

Solution

This looks like a bug with the standard verilog indent function, part of the standard vim distribution at runtime/indent/verilog.vim.

A search for verilog indent files on www.vim.org shows four options, including one labeled "bugfixes to vim indent for verilog : bugfixes: previous version was evaluating expressions inside comments". You could try that one, but it is the lowest-rated of the options. You could also try GitHub.

OTHER TIPS

To add to benjifishers answer since you are not specifying the indentation file the default version will be used runtime/indent/verilog.vim.

If you have not already install pathogen, I recommend that you do so, it makes switching syntax & indentation files very easy.

Basically it will allow you to add plugins as a single folder into ~/.vim/bundle, which also implies removeing the ones you do not want is easy as deleting a single folder. This is useful when trying out language plugins otherwise they often require files to be put in:

~/.vim/ftdetect
~/.vim/ftplugin
~/.vim/indent
~/.vim/syntax

The Verilog option on vim.org is probably lowly rated because it does not support SystemVerilog Keywords.

I have a SystemVerilog plugin which I use but do not think the re-indent function is fixed there.

Mine is based on nickjones verilog_systemverilog.
The latest under active development looks like nachumk's systemverilog.vim.

NB: for re-indentation I have this setup in my .vimrc which re-indents from ;g and keeps current position in the file.

"http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
function! Preserve(command)
  " Preparation: save last search, and cursor position.
  let _s=@/
  let l = line(".")
  let c = col(".")
  " Do the business:
  execute a:command
  " Clean up: restore previous search history, and cursor position
  let @/=_s
  call cursor(l, c)
endfunction

map ;g :call Preserve("normal! gg=G")<CR>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top