My Vim Setting for verilog/systemverilog coding
Backgroud
I started using Vim after I started working in the first company, because the platform was linux and we were not allowed to install any software. Actually it is not bad, I improved my Linux skill a lot on this limited platform.
I had tried to learn to use Vim before, but it was hard for me to remember the key and to switch between these modes. The platform forced me to use it and I started with using only basic operations like i
, Esc
, :w
and so on. After figuring out the rule, it was easier and easier to learn new operations.
Most of the time, I am coding in verilog. It doesn’t like other software languages which have plenty of excellent tools/IDE, free or not free, to use. Even the EDA tools that cost millions of dollors a year, the edit function of them is still bad. (Maybe they were not designed as an code editors.)
However, after 4 years tweaking, I think I have a relatively handy environment to code in verilog, at least for myself.
Tools
Emacs verilog mode
Yes, it is Emacs. I don’t know how to use Emacs but its verilog-mode is amazing! It saves my life in top-level module connection and many tedious signal name typing. Check here if you are not familar with it.
Even we can use the *
in systemverilog, I still prefer the traditional way. Because it is easier to debug on the source code when signals are given explicitly.
Although it is an Emacs function, we can call it using emacs --batch {filenames...} -f verilog-batch-auto
; and there is also a plugin to run it directly in Vim.
Some example:
- Argument lists
Before:
1 | module mod0(/*autoarg*/); |
After processed by verilog-mode:
1 | module mod0(/*autoarg*/ |
- Instantiations
Before:
1 | // mod0.v |
top0.v
after processed by verilog-mode:
1 | // top0.v |
Check here for more features:
Vim
The vim in my company is an old one(7.3), I managed to compile the latest one in my home dir. Therefore I can use the new features such as relative line number and install more new plugins without compatibility issue. (I learnt compiling code here; previously I only know apt-get
.)
Vim Plugins
These are the plugins which are useful in verilog coding.
Vundle is a plugin manager for vim. Just put the github repo in your .vimrc
to install and manage them.
Example:
1 | " Use the name directly from http://vim-scripts.org/vim/scripts.html |
The all plugins mentioned below can be install like this.
verilog_emacsauto.vim
By using this plugin, use\a
to expands all the verilog-mode autos(C-c C-a
in emacs) and use\d
to delete the autos(C-c C-d
in emacs);
vim-airline
provides a fancy status line for vim. I switched to this after vim-powerline going to maintenance mode.
This plugin can give different colors for different levels of parentheses, which helps to read complex code much easier.
This plugin can show vertical lines at each indent level.
Gives code highlighting and some other features for systemverilog.
Helps to align the code. For example:
1 | var_0 = 1; |
after applying :Tabularize /=
1 | var_0 = 1; |
And:
Aligning Text with Tabular.vim
For more details please check its github page.
Easier to make a column of increasing or decreasing numbers, dates, or daynames.
-
It allows you to use
for all your insert completion needs
other thoughts
There are some things that I would like to give a try if I have time.
- cscope
- snippet
- …