You can also use the align
command instead of align-regexp
. The difference is that align
automatically chooses the regular expression(s) to use based on the major-mode of the buffer. So if you are trying to align a block of variable initializations and assignments in a c-mode file, then it will automatically do the right thing without you needing to think of the regular expressions which are needed. Can be convenient.
For example select the following lines:
int x = 3;
double y = 9.0;
unsigned int z = 6;
const char c = 'A';
And type M-x align RET
. The result is:
int x = 3;
double y = 9.0;
unsigned int z = 6;
const char c = 'A';
I should add, though, that this will not always work. If there are no regular expressions defined for the major-mode of the current buffer, then the call to align
will do nothing. Then, you need to fall back on align-regexp
. But this is hardly a large inconvenience. I actually use align-regexp
fairly frequently. For convenience, I have defined an alias to save myself a few key-strokes:
(defalias 'ar #'align-regexp)
M-x
means either Alt+x or Esc followed by x.RET
means Enter. – Lysozyme