EasyAlign
EasyAlign is a plugin for doing character alignment that is nothing short of OCD.
Project address
https://github.com/junegunn/vim-easy-align
Installation
Modify
.vimrc
configuration, add the following configuration aftercall plug#begin()
Note: For use of the Vim plugin manager, see [plugin.md](../plugin.md#plugin management)
Run Vim and execute the command
:PlugInstall
, you may get the following prompt:
Usage
Configuration
Add
.vimrc
configuration as follows:
Experiment
Try the following operations in the code below:
First locate the cursor to any sentence in the above code, press
gaip<Space>
, you should get the following results
Keep the cursor still, press
gaip=
, you should get the following results
Keep the cursor still, press
u
, then pressgaip*=
, you should get the following results
The meaning of the keys is explained below:
gaip
ga
is the shortcut to enable EasyAlign, which we defined in the.vimrc
configuration file.ip
defines the action area, which can be done with any select action command,ip
selects the current paragraph, and if the cursor is on the first line of code,2j
can be used instead of.vimrc
. If the cursor is on the first line of code, you can use2j
instead ofip
.At this point, the word
:EasyAlign (_)
will appear in the command area, indicating that it is waiting for matching input.Press
<Space>
to align the first space.
gaip=
Same as above,
=
is to align the<equals sign>
.
gaip*=
To see the effect, undo the previous operation with
u
.The
=
preceded by*
is a descriptor that can be a number, representing the first equals sign, or a negative number, representing the the penultimate number, or an asterisk for all.
If you're sure you've changed the configuration as mentioned above, you can also try
gaip/
to align the comment section, and when executed, look at It will look like this
Explanation of Match Characters
The above mentioned <Space>
=
are special symbols defined in EasyAlign to indicate a certain type of character. These symbols are defined in EasyAlign to represent a certain type of character:
Note: The <Bar>
key mentioned in the table above is the |
key.
Try to align a markdown table by
gaip*|
in the above table.
Tips
Alignment method
When you are waiting for a match to be entered and :EasyAlign (_)
appears in the command area, you can press the <Enter>
key to select the alignment direction. Press once to switch to right alignment and display :EasyAlign[R] (_)
, press again to switch to center alignment and display :EasyAlign[R] (_)
, and press <Enter>
to switch to center alignment and display :EasyAlign[R] (_)
. toggle to center alignment and display :EasyAlign[C] (_)
, then press again to switch back to the default left alignment, and the display returns to its original state.
Try
gaip<Enter><Enter>*|
in the markdown table above.
Regular Matching
While waiting for a match to be typed, press the shortcut key <Ctrl-x>
to enter match mode, and then type in the matching feature you want. The special combination can be matched by typing in the matching feature you need. See the following text:
Try typing
gaip*<Ctrl-x>
, then it enters the regular matching mode, continue typing<[-=~]*<Enter>
and you will get the following result. The result is shown below.
More references
For more references, please refer to the introduction of project page
Last updated