sponsor Vim development Vim logo Vim Book Ad

align : Align the right ends of statements together.

 script karma  Rating 0/5, Downloaded by 835  Comments, bugs, improvements  Vim wiki

created by
Zohair Ahmad
 
script type
utility
 
description
I wrote this script to help write verilog files that were compatible with my
company's coding standard.

This script shifts the character under the cursor to a defined point. It can
thus be used to align the *right* side of code to beautify or to confirm to
coding standards.

Spaces are inserted before the current cursor position. The number of spaces
inserted aligns the text to the lines above it. For example, if you have the
following chunk of code.

reg [13:0] resultant  ;
reg  [7:0] bytea;

If you load the script and press ';;' while on the semicolon on the second line,
the text will become like so.

reg [13:0] resultant  ;
reg  [7:0] bytea      ;

NOTE: There has to be a previous aligned line for the script to make a match
from.

This can also be used as part of a recorded macro. For example, to align the
following lines of code, to the top line.

1   PORT_00       (port_00a       ),// Comment 1
2   PORT_01(port_01aa),// Comment 2
3   PORT_02(port_02aaa),// Comment 3
4   PORT_03(port_03aaaa),// Comment 4
5   PORT_04(port_04a),// Comment 5
6
7   PORT_T_00(port_t_00a),// Comment 6
8   PORT_T_01(port_t_01aa),// Comment 7
9   PORT_T_02(port_t_02aaa),// Comment 8
10  PORT_T_03(port_t_03aaaa),// Comment 9

We can record a macro. Place your cursor on the first char of line 2 (the digit
2) and press 'qzf(;;j^q'
  q   - start recording
  z   - record in register z
  f(  - go to first occurrence of (
  ;;  - align
  j   - move down
  ^   - go to start of line
  q   - end recording.

Now pressing @z on the start of line 3 will cause it to align. And the same for
all the other lines. The same can be done for the closing brackets to get the
following.

1   PORT_00       (port_00a       ), // Comment 1
2   PORT_01       (port_01aa      ), // Comment 2
3   PORT_02       (port_02aaa     ), // Comment 3
4   PORT_03       (port_03aaaa    ), // Comment 4
5   PORT_04       (port_04a       ), // Comment 5
6
7   PORT_T_00     (port_t_00a     ), // Comment 6
8   PORT_T_01     (port_t_01aa    ), // Comment 7
9   PORT_T_02     (port_t_02aaa   ), // Comment 8
10  PORT_T_03     (port_t_03aaaa  ), // Comment 9
 
install details
Put the script in some folder (lets say $ALIGN)
add this to your ~/.vimrc

source $ALIGN/align.vim
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
align.tar.gz 1.0 2011-02-24 7.0 Zohair Ahmad Initial upload
ip used for rating: 18.118.0.240

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github