Quantcast
Channel: acassis – Alan C. Assis
Viewing all articles
Browse latest Browse all 870

Creating a VIM macro to align variable definition on header files

$
0
0

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


Viewing all articles
Browse latest Browse all 870