mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-14 04:43:48 -05:00
Implement special keys to switch option values in interactive mode
With this commit, we can now change option values in interactive mode with the
folowing special keys
- CTRL-L left_margin
- CTRL-R right_margin
- CTRL-D delimiter_align
- CTRL-I indentation
- CTRL-U ignore_unmatched
- CTRL-G ignore_groups
('ignores' option has been renamed to 'ignore_groups', but backward-compatible)
This commit is contained in:
@@ -116,21 +116,7 @@ You can even omit spaces between the arguments, so concisely (or cryptically):
|
||||
|
||||
- :EasyAlign*/[:;]\+/{'s':1,'l':''}
|
||||
|
||||
Available options are as follows.
|
||||
|
||||
| Atrribute | Type | Default |
|
||||
| ---------------- | ---------------- | ----------------------------- |
|
||||
| left_margin | number or string | 0 |
|
||||
| right_margin | number or string | 0 |
|
||||
| stick_to_left | boolean | 0 |
|
||||
| ignore_unmatched | boolean | 1 |
|
||||
| ignores | array | ['String', 'Comment'] |
|
||||
| delimiter_align | string | 'r' |
|
||||
| | | (right, left, center) |
|
||||
| indentation | string | 'k' |
|
||||
| | | (keep, shallow, deep, none) |
|
||||
| mode_sequence | string | (Depends on field number and |
|
||||
| | | selected alignment mode) |
|
||||
Available options will be shown later in the document.
|
||||
|
||||
|
||||
Partial alignment in blockwise-visual mode
|
||||
@@ -140,7 +126,50 @@ In blockwise-visual mode (CTRL-V), EasyAlign command aligns only
|
||||
the selected text in the block, instead of the whole lines in the range.
|
||||
|
||||
|
||||
Ignoring delimiters in comments or strings *g:easy_align_ignores*
|
||||
Alignment options
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
Available options are as follows.
|
||||
|
||||
| Atrribute | Type | Default |
|
||||
| ---------------- | ---------------- | ----------------------------- |
|
||||
| left_margin | number or string | 0 |
|
||||
| right_margin | number or string | 0 |
|
||||
| stick_to_left | boolean | 0 |
|
||||
| ignore_unmatched | boolean | 1 |
|
||||
| ignore_groups | array | ['String', 'Comment'] |
|
||||
| delimiter_align | string | 'r' |
|
||||
| | | (right, left, center) |
|
||||
| indentation | string | 'k' |
|
||||
| | | (keep, shallow, deep, none) |
|
||||
| mode_sequence | string | (Depends on field number and |
|
||||
| | | selected alignment mode) |
|
||||
|
||||
|
||||
Some of the options can be specified using corresponding global variables.
|
||||
|
||||
| Option | Global variable |
|
||||
| ------------------ | ------------------------------- |
|
||||
| ignore_groups | `g:easy_align_ignore_groups` |
|
||||
| ignore_unmatched | `g:easy_align_ignore_unmatched` |
|
||||
| delimiter_align | `g:easy_align_delimiter_align` |
|
||||
| indentation | `g:easy_align_indentation` |
|
||||
|
||||
|
||||
In interactive mode, you can switch some of the alignment options using special
|
||||
keys listed below.
|
||||
|
||||
| Key | Option | Values |
|
||||
| ------ | ---------------- | -------------------------------------------------- |
|
||||
| CTRL-I | indentation | shallow, deep, none, keep |
|
||||
| CTRL-L | left_margin | Input number or string |
|
||||
| CTRL-R | right_margin | Input number or string |
|
||||
| CTRL-D | delimiter_align | left, center, right |
|
||||
| CTRL-U | ignore_unmatched | 0, 1 |
|
||||
| CTRL-G | ignore_groups | [], ['String'], ['Comment'], ['String', 'Comment'] |
|
||||
|
||||
|
||||
Ignoring delimiters in comments or strings *g:easy_align_ignore_groups*
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
EasyAlign can be configured to ignore delimiters in certain syntax
|
||||
@@ -150,7 +179,7 @@ that are highlighted as code comments or strings are ignored.
|
||||
" Default:
|
||||
" If a delimiter is in a highlight group whose name matches
|
||||
" any of the followings, it will be ignored.
|
||||
let g:easy_align_ignores = ['Comment', 'String']
|
||||
let g:easy_align_ignore_groups = ['Comment', 'String']
|
||||
|
||||
For example, the following paragraph
|
||||
|
||||
@@ -176,13 +205,15 @@ becomes as follows on '<Enter>:' (or `:EasyAlign:`)
|
||||
|
||||
Naturally, this feature only works when syntax highlighting is enabled.
|
||||
|
||||
You can change the default rule by using one of these 3 methods.
|
||||
You can change the default rule by using one of these 4 methods.
|
||||
|
||||
1. Define global `g:easy_align_ignores` list
|
||||
2. Define a custom rule in `g:easy_align_delimiters` with 'ignores' option
|
||||
3. Provide 'ignores' option to `:EasyAlign` command. e.g. :EasyAlign:{'is':[]}
|
||||
1. Press CTRL-G in interactive mode to switch groups
|
||||
2. Define global `g:easy_align_ignore_groups` list
|
||||
3. Define a custom rule in `g:easy_align_delimiters` with 'ignore_groups' option
|
||||
4. Provide 'ignore_groups' option to `:EasyAlign` command.
|
||||
e.g. :EasyAlign:{'is':[]}
|
||||
|
||||
For example if you set 'ignores' option to be an empty list, you get
|
||||
For example if you set 'ignore_groups' option to be an empty list, you get
|
||||
|
||||
{
|
||||
# Quantity of apples: 1
|
||||
@@ -220,12 +251,13 @@ this is usually what we want.
|
||||
grapefruits: 3
|
||||
}
|
||||
|
||||
However, this default behavior is also configurable by using one of these 3
|
||||
However, this default behavior is also configurable by using one of these 4
|
||||
methods.
|
||||
|
||||
1. Set the global `g:easy_align_ignore_unmatched` variable to 0
|
||||
2. Define a custom alignment rule with 'ignore_unmatched' option set to 0
|
||||
3. Provide 'ignore_unmatched' option to `:EasyAlign` command.
|
||||
1. Press CTRL-U in interactive mode to toggle 'ignore_unmatched' option
|
||||
2. Set the global `g:easy_align_ignore_unmatched` variable to 0
|
||||
3. Define a custom alignment rule with 'ignore_unmatched' option set to 0
|
||||
4. Provide 'ignore_unmatched' option to `:EasyAlign` command.
|
||||
e.g. :EasyAlign:{'iu':0}
|
||||
|
||||
Then we get,
|
||||
@@ -268,6 +300,8 @@ And on ':EasyAlign={'da':c}', center-aligned.
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
|
||||
In interactive mode, you can change the option value with `CTRL-D` key.
|
||||
|
||||
|
||||
Adjusting indentation *g:easy_align_indentation*
|
||||
-------------------------------------------------------------------------
|
||||
@@ -317,6 +351,8 @@ But then again we have 'indentation' option. See the following example.
|
||||
|
||||
Notice that 'idt' is fuzzy-matched to 'indentation'.
|
||||
|
||||
In interactive mode, you can change the option value with `CTRL-I` key.
|
||||
|
||||
|
||||
Left/right/center mode switch in interactive mode
|
||||
-------------------------------------------------------------------------
|
||||
@@ -396,8 +432,8 @@ you can extend the rules by setting a dictionary named
|
||||
|
||||
let g:easy_align_delimiters = {
|
||||
\ '>': { 'pattern': '>>\|=>\|>' },
|
||||
\ '/': { 'pattern': '//\+\|/\*\|\*/', 'ignores': ['String'] },
|
||||
\ '#': { 'pattern': '#\+', 'ignores': ['String'] },
|
||||
\ '/': { 'pattern': '//\+\|/\*\|\*/', 'ignore_groups': ['String'] },
|
||||
\ '#': { 'pattern': '#\+', 'ignore_groups': ['String'] },
|
||||
\ ']': {
|
||||
\ 'pattern': '[[\]]',
|
||||
\ 'left_margin': 0,
|
||||
|
||||
Reference in New Issue
Block a user