vhda / verilog_systemverilog.vim

Verilog/SystemVerilog Syntax and Omni-completion
359 stars 86 forks source link

default indent (question) #203

Closed brayden-jo closed 2 years ago

brayden-jo commented 3 years ago

Thank you for making a good plugin. I have a simple question, I review the document but I didn't find a proper solution yet.

This plug-in seems to use default 4-space of indent. Can I turn-off this feature ? We usually the coding style which starts with column 0. Please check below two coding style.

// current
module (
    clk, 
    reset_n,
    i_data,
    o_data
);

    input clk;
    input reset_n;

endmodule
// new
module (
    clk, 
    reset_n,
    i_data,
    o_data
);

input clk;                               // no indent
input reset_n;

always @ (posedge clk or negedge reset_n) begin
    if (!reset_n) begin
        o_data <= 4'b0;
   end else begin
       o_data <= i_data;
   end
end

endmodule
brayden-jo commented 3 years ago

I added below line to .vimrc but it does not works.

let g:verilog_disable_indent_lst = "module,class,interface"
vhda commented 3 years ago

Hi @brayden-jo,

That should work exactly as you need if you also include "eos" in the comma separated list. And the plugin will follow by default your 'shiftwidth' setting. This what I get with set sw=2 and let g:verilog_disable_indent_lst="eos":

// new
module (
  clk,
  reset_n,
  i_data,
  o_data
);

  input clk;                               // no indent
  input reset_n;

  always @ (posedge clk or negedge reset_n) begin
    if (!reset_n) begin
      o_data <= 4'b0;
    end else begin
      o_data <= i_data;
    end
  end

endmodule

This what I get with let g:verilog_disable_indent_lst="eos,module":

// new
module (
  clk,
  reset_n,
  i_data,
  o_data
);

input clk;                               // no indent
input reset_n;

always @ (posedge clk or negedge reset_n) begin
  if (!reset_n) begin
    o_data <= 4'b0;
  end else begin
    o_data <= i_data;
  end
end

endmodule

Please try disabling other plugins and/or settings that could be affecting this behavior.

Hope this helps, Vitor

brayden-jo commented 3 years ago

@vhda , Thanks you for your reply.

When I set the below setting within the vim, it works well.

let g:verilog_disable_indent_lst = "module,class,interface"

But as I mentioned before, it doesn't work with .vimrc file. I delete all plugins and use the simplest .vimrc as below:

call plug#begin('~/.vim/plugged')
    Plug 'vhda/verilog_systemverilog.vim'
call plug#end()

let g:verilog_disable_indent_lst="eos,module"

Currently I use the this command in the vim to apply the let g:~~~~ configure.

source ~/.vimrc

I am using the CentOS7 default vim.

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 26 2017 20:42:41)
Included patches: 1-586
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     +gettext         -mzscheme        +textobjects
+channel         -hangul_input    +netbeans_intg   +timers
+cindent         +iconv           +num64           +title
-clientserver    +insert_expand   +packages        -toolbar
-clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl/dyn        +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python/dyn      +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      +lua/dyn         +rightleft       +writebackup
+diff            +menu            +ruby/dyn        -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      -mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        +mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax          
+farsi           +mouse_netterm   +tag_binary      
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim80"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1   -DEXITFREE    
Linking: gcc   -L. -Wl,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -Wl,-z,relro  -L/usr/local/lib -Wl,--as-needed -o vim        -lm -lnsl  -lselinux  -lncurses -lacl -lattr -lgpm -ldl   -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc       
vhda commented 3 years ago

Instead of sourcing vimrc just open vim and run the following command:

:let g:verilog_disable_indent_lst

Does this show the value you defined in the vimrc? Then try opening a verilog file and check this command again. Could you also confirm the filetype value in the verilog file?

:set filetype
brayden-jo commented 3 years ago

@vhda , when I run the vim and run the following command:

:let g:verilog_disable_indent_lst

default options is shown as below

g:verilog disable indent lst eos

let g command in .vimrc doesn't seem to work.

when i run the :set filetype, I can see the 'filetype=verilog systemverilog'

Thanks.

brayden-jo commented 3 years ago

Screenshot from 2021-03-04 16-44-50

vhda commented 3 years ago

Hi @brayden-jo, Sorry for the delayed reply.

Are you saying that g:verilog_disable_indent_lst variable does not work in .vimrc. But what about setting it dynamically? That is, if you open a Verilog file and set this variable, do you see indentation start to work correctly? I'm running out of ideas. Everything looks good and it should be working!

brayden-jo commented 3 years ago
vim

@vhda ,

dynamically setting doesn't work too for the *v/sv file. For reference, my colleague using centos7 also shows the same problem.

Is there any workaround to fix the plugin directly?

"module,class,interface" is the default list for the our coding style.

vhda commented 3 years ago

I've just tried on my side with a clean .vimrc and everything is working as expected. I can try it in CentOS during this week just to confirm, but I'm really confident that shouldn't be the issue. Using the example file above, try the following:

gg=G

This will indent the complete file. This is the result with default settings: image Then I set the variable to "eos,module" and get this: after re-indenting: image

netvolcano commented 2 years ago

I had the same issue and found a way to solve it. I suggest to add the following lines in the plugin\verilog_systemverilog.vim. When I put my setting the .vimrc file, this following statements will not overwrite my setting.

" Global plugin settings
if !exists("g:verilog_disable_indent_lst")
    let g:verilog_disable_indent_lst="eos"
endif