đĄWelcome to the fifth edition of the FPGA Design Digest.
This edition takes a slight detour from my usual topics. Instead of diving into RTL or FPGA design concepts, or even interview preparation, I want to address a common issue Iâve encountered throughout my career as an RTL Designer: poor coding styles and code management.
One of the most common themes is mis-aligned code, with non-uniform tab spacing. In this video post (my first one!!), I want to show a quick and easy method that I use to align code blocks in Vim. I do not use any fancy IDEs, so I cannot comment on the ease of doing this in those tools.
If you have your own tried and tested method to handle this problem, please let me know in the Comments section. If you find this content useful, please share it with your community. đ
If I had a dollar for every instance of bad, mis-aligned code that I come across, well, I would have a healthy income generating side-hustle. The most common reason for pushing up âuglyâ code is laziness, and a close second would be lack of knowledge of how to quickly accomplish the task.
How to align the â=â operator for multiple assign statements?
The video below shows how to quickly accomplish the task. You will not have to touch the mouse in this process. This method can be applied to a lot of other alignment scenarios as well.
âĄImportant
Row and column cursors can be turned on with the following commands
:set cursorline :set cursorcolumn
Additionally, you can customize the highlight colors using the
highlight
command. For example, to change the background color of the highlighted column, you can add this to your.vimrc
:highlight CursorColumn ctermbg=lightgrey
To enter Visual Block mode in Vim, follow these steps:
Ensure youâre in Normal mode: Press
Esc
to make sure youâre not in Insert or any other mode.Activate Visual Block mode: Press
Ctrl+v
. Youâll see-- VISUAL BLOCK --
at the bottom of the screen.
After selecting the text in Visual Block Mode, enter Command Mode
Press
:
. This will automatically insert:'<,'>
at the command line, indicating the range of your visual selection.Perform the substitution:
Type
s/old/new/g
and pressEnter
. Replaceold
with the text you want to change andnew
with the new text.
Thank you for the support.