Creating a VIM macro to align variable definition on header files

I was looking for a way to align registers definitions like these:

#define REGISTER_XYZ 0x0001
#define REGISTER_A 0x0002

And I found this nice tip:

qa -- Record a macro in hotkey a
0 -- Go to the beginning of the line
f= -- Go to the first equals sign
100i <Esc> -- (There's a single space after the i, and the <Esc> means press escape, don't type "<Esc>".) Insert 100 spaces
8| -- Go to the 8th column (sorry, you'll have to manually figure out which column to align to)
dw -- Delete until the next non-space character
j -- Go to the next line
q -- Stop recording.

In my case I just replaced the “f=” with “f0” and “8|” with “33|”

Source: https://stackoverflow.com/questions/6154306/how-to-insert-spaces-up-to-column-x-to-line-up-things-in-columns

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s