I remember this was possible in emacs, but don't know how. If I hav开发者_开发技巧e something like:
'abc' => 1, 'abcabc' =>2, 'abcabcabc' => 3,
How can I align the keys, arrows and values to something like this?
'abc' => 1, 'abcabc' => 2, 'abcabcabc' => 3,
Cheers
Select the region.
Type
M-x align-regexp RET
Type
=
and hit enter.
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)
精彩评论