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
2
3
4
5
module mod0(/*autoarg*/);
input a;
input b;
output c;
endmodule

After processed by verilog-mode:

1
2
3
4
5
6
7
8
9
10
module mod0(/*autoarg*/
// Outputs
c,
// Inputs
a, b
);
input a;
input b;
output c;
endmodule
  • Instantiations
    Before:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// mod0.v
module mod0 (i_0, o_0);
input i_0;
output [31:0] o_0;
endmodule

// top0.v
module top0 (/*autoarg*/);
/*autoinput*/
/*autooutput*/

mod0 u_mod0 (/*autoinst*/);
endmodule

top0.v after processed by verilog-mode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// top0.v
module top0 (/*autoarg*/
// Outputs
o_0,
// Inputs
i_0
);
/*autoinput*/
// Beginning of automatic inputs (from unused autoinst inputs)
input i_0; // To u_mod0 of mod0.v
// End of automatics
/*autooutput*/
// Beginning of automatic outputs (from unused autoinst outputs)
output [31:0] o_0; // From u_mod0 of mod0.v
// End of automatics

mod0 u_mod0 (/*autoinst*/
// Outputs
.o_0 (o_0[31:0]),
// Inputs
.i_0 (i_0));
endmodule

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
2
3
4
5
6
" Use the name directly from http://vim-scripts.org/vim/scripts.html
Plugin 'vividchalk.vim'

" Plugin from Github repo
Plugin 'tomasr/molokai'

The all plugins mentioned below can be install like this.


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
2
var_0 = 1;
long_var_0 = 10;

after applying :Tabularize /=

1
2
var_0      = 1;
long_var_0 = 10;

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.

  • supertab

    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