mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-10 19:03:50 -05:00
Update README
This commit is contained in:
54
README.md
54
README.md
@@ -3,20 +3,21 @@ vim-easy-align
|
|||||||
|
|
||||||
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
||||||
|
|
||||||
Features:
|
|
||||||
|
|
||||||
- Optimized for code editing
|
|
||||||
- Requires minimal keystrokes
|
|
||||||
- Extensible alignment rules
|
|
||||||
- Aligns text around either _all or n-th_ occurrence(s) of the delimiter
|
|
||||||
- Ignores delimiters in certain syntax highlighting groups (e.g. comments, strings)
|
|
||||||
- Ignores lines without a matching delimiter
|
|
||||||
|
|
||||||
Demo
|
Demo
|
||||||
----
|
----
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- Optimized for code editing
|
||||||
|
- Designed to require minimal keystrokes
|
||||||
|
- Extensible alignment rules
|
||||||
|
- Aligns text around either _all or n-th_ occurrence(s) of the delimiter
|
||||||
|
- Ignores delimiters in certain syntax highlight groups (e.g. comments, strings)
|
||||||
|
- Ignores lines without a matching delimiter
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@@ -34,7 +35,8 @@ Usage
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
_vim-easy-align_ defines interactive `:EasyAlign` command in the visual mode.
|
_vim-easy-align_ defines interactive `:EasyAlign` command in the visual mode.
|
||||||
For convenience, it is advised that you define a mapping for triggering it in your `.vimrc`.
|
For convenience, it is advised that you define a mapping for triggering it in
|
||||||
|
your `.vimrc`.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
vnoremap <silent> <Enter> :EasyAlign<cr>
|
vnoremap <silent> <Enter> :EasyAlign<cr>
|
||||||
@@ -96,9 +98,9 @@ my_hash = { :a => 1,
|
|||||||
:aaa => 3 }
|
:aaa => 3 }
|
||||||
```
|
```
|
||||||
|
|
||||||
In non-blockwise visual mode (`v` / `V`), `<Enter>=` won't work since the assignment
|
In non-blockwise visual mode (`v` / `V`), `<Enter>=` won't work since the
|
||||||
operator in the first line gets in the way.
|
assignment operator in the first line gets in the way. So we instead enter
|
||||||
So we instead enter blockwise-visual mode (`CTRL-V`), and select the text *around*
|
blockwise-visual mode (`CTRL-V`), and select the text *around*
|
||||||
`=>` operators, then press `<Enter>=`.
|
`=>` operators, then press `<Enter>=`.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@@ -113,17 +115,17 @@ since the same can be easily done using the negative field number: `<Enter>-=`
|
|||||||
Options
|
Options
|
||||||
-------
|
-------
|
||||||
|
|
||||||
| Option | Type | Default | Description |
|
| Option | Type | Default | Description |
|
||||||
| ----------------------------- | ---------- | --------------------- | ----------------------------------------------------- |
|
| ----------------------------- | ---------- | --------------------- | -------------------------------------------------- |
|
||||||
| g:easy_align_ignores | list | ['String', 'Comment'] | Ignore delimiters in these syntax highlighting groups |
|
| g:easy_align_ignores | list | ['String', 'Comment'] | Ignore delimiters in these syntax highlight groups |
|
||||||
| g:easy_align_ignore_unmatched | boolean | `1` | Ignore lines without matching delimiter |
|
| g:easy_align_ignore_unmatched | boolean | `1` | Ignore lines without matching delimiter |
|
||||||
| g:easy_align_delimiters | dictionary | `{}` | Extend or override alignment rules |
|
| g:easy_align_delimiters | dictionary | `{}` | Extend or override alignment rules |
|
||||||
|
|
||||||
### Ignoring delimiters in comments or strings
|
### Ignoring delimiters in comments or strings
|
||||||
|
|
||||||
EasyAlign can be configured to ignore delimiters in certain highlight groups,
|
EasyAlign can be configured to ignore delimiters in certain syntax highlight
|
||||||
such as code comments or strings. By default, delimiters that are highlighted as
|
groups, such as code comments or strings. By default, delimiters that are
|
||||||
code comments or strings are ignored.
|
highlighted as code comments or strings are ignored.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Default:
|
" Default:
|
||||||
@@ -132,7 +134,7 @@ code comments or strings are ignored.
|
|||||||
let g:easy_align_ignores = ['Comment', 'String']
|
let g:easy_align_ignores = ['Comment', 'String']
|
||||||
```
|
```
|
||||||
|
|
||||||
For example,
|
For example, the following paragraph
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
{
|
{
|
||||||
@@ -145,7 +147,7 @@ For example,
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
becomes
|
becomes as follows on `<Enter>:`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
{
|
{
|
||||||
@@ -158,9 +160,9 @@ becomes
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Naturally, this only works when syntax highlighting is enabled.
|
Naturally, this feature only works when syntax highlighting is enabled.
|
||||||
|
|
||||||
You can override `g:easy_align_ignores` to change the rule.
|
You can change the default rule by defining `g:easy_align_ignores` array.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Ignore nothing!
|
" Ignore nothing!
|
||||||
@@ -184,7 +186,7 @@ Satisfied? :satisfied:
|
|||||||
|
|
||||||
### Ignoring unmatched lines
|
### Ignoring unmatched lines
|
||||||
|
|
||||||
Lines without a matching delimiter are ignored as well (except in
|
Lines without any matching delimiter are ignored as well (except in
|
||||||
right-justification mode).
|
right-justification mode).
|
||||||
|
|
||||||
For example, when aligning the following code block around the colons,
|
For example, when aligning the following code block around the colons,
|
||||||
|
|||||||
@@ -70,16 +70,16 @@ the selected text in the block, instead of the whole lines in the range.
|
|||||||
Ignoring delimiters in comments or strings *g:easy_align_ignores*
|
Ignoring delimiters in comments or strings *g:easy_align_ignores*
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
EasyAlign can be configured to ignore delimiters in certain highlight
|
EasyAlign can be configured to ignore delimiters in certain syntax
|
||||||
groups, such as code comments or strings. By default, delimiters that are
|
highlight groups, such as code comments or strings. By default, delimiters
|
||||||
highlighted as code comments or strings are ignored.
|
that are highlighted as code comments or strings are ignored.
|
||||||
|
|
||||||
" Default:
|
" Default:
|
||||||
" If a delimiter is in a highlight group whose name matches
|
" If a delimiter is in a highlight group whose name matches
|
||||||
" any of the followings, it will be ignored.
|
" any of the followings, it will be ignored.
|
||||||
let g:easy_align_ignores = ['Comment', 'String']
|
let g:easy_align_ignores = ['Comment', 'String']
|
||||||
|
|
||||||
For example,
|
For example, the following paragraph
|
||||||
|
|
||||||
{
|
{
|
||||||
# Quantity of apples: 1
|
# Quantity of apples: 1
|
||||||
@@ -90,7 +90,7 @@ For example,
|
|||||||
'grape:fruits': 3
|
'grape:fruits': 3
|
||||||
}
|
}
|
||||||
|
|
||||||
becomes
|
becomes as follows on `<Enter>:`:
|
||||||
|
|
||||||
{
|
{
|
||||||
# Quantity of apples: 1
|
# Quantity of apples: 1
|
||||||
@@ -101,8 +101,11 @@ becomes
|
|||||||
'grape:fruits': 3
|
'grape:fruits': 3
|
||||||
}
|
}
|
||||||
|
|
||||||
You can override `g:easy_align_ignores` to change the rule.
|
Naturally, this feature only works when syntax highlighting is enabled.
|
||||||
|
|
||||||
|
You can change the default rule by defining `g:easy_align_ignores` array.
|
||||||
|
|
||||||
|
" Ignore nothing!
|
||||||
let g:easy_align_ignores = []
|
let g:easy_align_ignores = []
|
||||||
|
|
||||||
Then you get,
|
Then you get,
|
||||||
@@ -120,7 +123,7 @@ Then you get,
|
|||||||
Handling unmatched lines *g:easy_align_ignore_unmatched*
|
Handling unmatched lines *g:easy_align_ignore_unmatched*
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
Lines without a matching delimiter are ignored as well (except in
|
Lines without any matching delimiter are ignored as well (except in
|
||||||
right-justification mode).
|
right-justification mode).
|
||||||
|
|
||||||
For example, when aligning the following code block around the colons,
|
For example, when aligning the following code block around the colons,
|
||||||
|
|||||||
Reference in New Issue
Block a user