mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-17 06:13:41 -05:00
Compare commits
231 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9815a55dbc | ||
|
|
12dd631697 | ||
|
|
1cd724dc23 | ||
|
|
14c693dfe5 | ||
|
|
d3f8e64261 | ||
|
|
3b395bd5ba | ||
|
|
05cc60d222 | ||
|
|
4be4101ad5 | ||
|
|
3800a5405c | ||
|
|
2e27fe55ad | ||
|
|
0cb6b98fc1 | ||
|
|
dd98d0a895 | ||
|
|
d1b68f9dd0 | ||
|
|
4fb4c1056c | ||
|
|
7cb559eb70 | ||
|
|
9ebd0e82da | ||
|
|
9e6207246c | ||
|
|
4732f10155 | ||
|
|
cd124c2c0b | ||
|
|
ed65b47f1b | ||
|
|
fac9f4dd75 | ||
|
|
0db4ea6132 | ||
|
|
504eab0f59 | ||
|
|
98e0b493ac | ||
|
|
1206c65dcb | ||
|
|
a1118be7d9 | ||
|
|
c62d124be6 | ||
|
|
883c6b67a0 | ||
|
|
32591ec4d4 | ||
|
|
ac9aa14ae4 | ||
|
|
cafe55dd65 | ||
|
|
6c276c37ad | ||
|
|
1744414e7e | ||
|
|
246139c57c | ||
|
|
3afd4540ed | ||
|
|
2782c1d0db | ||
|
|
d983381a99 | ||
|
|
52814ccd96 | ||
|
|
aa1ba68ea0 | ||
|
|
b8abc366a6 | ||
|
|
f6586bad39 | ||
|
|
44216b0a2c | ||
|
|
2595ebf933 | ||
|
|
6bc221c285 | ||
|
|
21697776b4 | ||
|
|
09167c79c9 | ||
|
|
cbb005ee71 | ||
|
|
ec15731bc9 | ||
|
|
eee4735770 | ||
|
|
5e2a588403 | ||
|
|
2fa6a040f6 | ||
|
|
f9a49e441d | ||
|
|
fc9555cd65 | ||
|
|
a98c1ccc99 | ||
|
|
0aa6289d8c | ||
|
|
cc8966c0a5 | ||
|
|
da281d78d3 | ||
|
|
8e8629c0cd | ||
|
|
a9f593fdf8 | ||
|
|
d87ea32cfe | ||
|
|
11a6b03e7e | ||
|
|
ba54df53ca | ||
|
|
d041e17bba | ||
|
|
2ab86911cb | ||
|
|
4929841a7a | ||
|
|
12792cd60f | ||
|
|
f7213f30f3 | ||
|
|
f44c325aa2 | ||
|
|
dc4786841e | ||
|
|
46abd8fb92 | ||
|
|
af39e544ca | ||
|
|
49c7133328 | ||
|
|
4298395085 | ||
|
|
e7fca89dde | ||
|
|
4b706efeb3 | ||
|
|
9bb987599a | ||
|
|
b8e93f96b8 | ||
|
|
6d85e93476 | ||
|
|
9271fc3f8f | ||
|
|
d3eec7fa8b | ||
|
|
62387b78e0 | ||
|
|
f400e4d8d1 | ||
|
|
9716fb3917 | ||
|
|
353ae9b071 | ||
|
|
ba4ba6e3c4 | ||
|
|
da284f908e | ||
|
|
8d4d5b7941 | ||
|
|
165bda1d95 | ||
|
|
ddc1e00b81 | ||
|
|
462a800064 | ||
|
|
3921d0bab3 | ||
|
|
ea1ea51ef1 | ||
|
|
2daae46a43 | ||
|
|
2b119f9bb6 | ||
|
|
15bcbc9499 | ||
|
|
54e6b5d866 | ||
|
|
1f28ce346e | ||
|
|
2832a76cea | ||
|
|
1a232ac19b | ||
|
|
a76cfdb8ae | ||
|
|
c3a7842b0d | ||
|
|
3cc564bd68 | ||
|
|
6e2264672a | ||
|
|
bec3e94383 | ||
|
|
7f0fccba0b | ||
|
|
aa62ca4603 | ||
|
|
831cecdaf2 | ||
|
|
37fa908d04 | ||
|
|
256e5b83ab | ||
|
|
cb7306341c | ||
|
|
7b82a1e496 | ||
|
|
ad2df21039 | ||
|
|
4c2808d13c | ||
|
|
124654ec46 | ||
|
|
ab4b72addf | ||
|
|
cdc648f5a4 | ||
|
|
438b5312ee | ||
|
|
e24f8479a5 | ||
|
|
9d626dd765 | ||
|
|
7490aa61d7 | ||
|
|
aa42666f10 | ||
|
|
9951cad2d0 | ||
|
|
cb5041ba67 | ||
|
|
7019edb08c | ||
|
|
247f69bf3f | ||
|
|
133588b181 | ||
|
|
fb8cf1d54a | ||
|
|
013fb54dd1 | ||
|
|
2bf1b2164d | ||
|
|
bab23a1917 | ||
|
|
fa26fd7b42 | ||
|
|
a4a1e27395 | ||
|
|
98bd9fe6f0 | ||
|
|
f944f5bf29 | ||
|
|
484b4ba5ec | ||
|
|
9d3afa6206 | ||
|
|
4c6a8c174d | ||
|
|
3304f4e95a | ||
|
|
e4f86274e3 | ||
|
|
2d575bcc25 | ||
|
|
8a783c2125 | ||
|
|
5230a2402f | ||
|
|
94a750e03e | ||
|
|
afc95b5ed7 | ||
|
|
1d2c58c06a | ||
|
|
4cdc450126 | ||
|
|
7e1be152dc | ||
|
|
c61a11d150 | ||
|
|
2797baca6c | ||
|
|
663264ed39 | ||
|
|
df75520f72 | ||
|
|
a2d52611ee | ||
|
|
fce0a103ff | ||
|
|
1752bf567b | ||
|
|
003194a47f | ||
|
|
c1c6f32e8c | ||
|
|
71edb17182 | ||
|
|
8951e13cf8 | ||
|
|
a998aee45d | ||
|
|
912bf6ca93 | ||
|
|
9cf4fde00c | ||
|
|
5f5cd49e95 | ||
|
|
639ade715b | ||
|
|
a1f2a697a5 | ||
|
|
0fb127cee6 | ||
|
|
d3803b927d | ||
|
|
40a06e3d36 | ||
|
|
11e0623959 | ||
|
|
e9b6418280 | ||
|
|
9f9d18ca71 | ||
|
|
301bdbcfc7 | ||
|
|
56e498a57d | ||
|
|
c0a500728c | ||
|
|
2e0f9a73cd | ||
|
|
6cac16dc3d | ||
|
|
6b275b8a46 | ||
|
|
25fec2e955 | ||
|
|
01337b9c4e | ||
|
|
0f70b20fdb | ||
|
|
61be5b3abf | ||
|
|
2ad49b24f0 | ||
|
|
5058de6f4c | ||
|
|
4c5d6d9e82 | ||
|
|
12c319a8ac | ||
|
|
62314afcaf | ||
|
|
cef26cdef9 | ||
|
|
659e2ff513 | ||
|
|
481a88f601 | ||
|
|
6fb4f57b5a | ||
|
|
beb986ebc3 | ||
|
|
5222db47cf | ||
|
|
74003c0297 | ||
|
|
999e1ff68e | ||
|
|
11a74c4176 | ||
|
|
e7e7a80afb | ||
|
|
29e5cd1d19 | ||
|
|
5c6558bd1b | ||
|
|
b6625f6d2b | ||
|
|
d4277a0298 | ||
|
|
d31e6ed257 | ||
|
|
1e2af43a64 | ||
|
|
0fb997d5ab | ||
|
|
90a5487974 | ||
|
|
aad5012615 | ||
|
|
0166077e16 | ||
|
|
3c4b7af9b5 | ||
|
|
5e6e60d620 | ||
|
|
712bab8c72 | ||
|
|
0546969c6b | ||
|
|
8805ec3834 | ||
|
|
96608ee5ef | ||
|
|
7d031956ab | ||
|
|
c4dbfece32 | ||
|
|
a2811dc253 | ||
|
|
5e4ec85956 | ||
|
|
b3281fb19a | ||
|
|
10a4176159 | ||
|
|
edba1827ed | ||
|
|
1cf343a271 | ||
|
|
c66f35ad39 | ||
|
|
2486b9c6df | ||
|
|
20124bc622 | ||
|
|
2a2625014b | ||
|
|
375da6858a | ||
|
|
06d5bcb911 | ||
|
|
badb701721 | ||
|
|
ea84b43062 | ||
|
|
bd8327499a | ||
|
|
057be51067 | ||
|
|
6d841110af | ||
|
|
ec456f82a6 |
4
.gitattributes
vendored
4
.gitattributes
vendored
@@ -1,5 +1,7 @@
|
||||
.travis.yml export-ignore
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
doc/tags export-ignore
|
||||
README.md export-ignore
|
||||
*.md export-ignore
|
||||
zip export-ignore
|
||||
test/* export-ignore
|
||||
|
||||
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
language: vim
|
||||
|
||||
before_script: |
|
||||
git clone https://github.com/junegunn/vader.vim.git
|
||||
git clone https://github.com/tpope/vim-repeat
|
||||
|
||||
script: |
|
||||
vim -Nu <(cat << VIMRC
|
||||
filetype off
|
||||
set rtp+=vader.vim
|
||||
set rtp+=vim-repeat
|
||||
set rtp+=.
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
VIMRC) -c 'Vader! test/*' > /dev/null
|
||||
322
EXAMPLES.md
322
EXAMPLES.md
@@ -1,33 +1,61 @@
|
||||
vim: set scrolloff=1 buftype=nofile colorcolumn=:
|
||||
easy-align examples
|
||||
===================
|
||||
|
||||
vim-easy-align examples
|
||||
=======================
|
||||
Open this document in your Vim and try it yourself.
|
||||
|
||||
This document assumes that you have the following mappings in your .vimrc.
|
||||
|
||||
```vim
|
||||
" Start interactive EasyAlign in visual mode (e.g. vipga)
|
||||
xmap ga <Plug>(EasyAlign)
|
||||
|
||||
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
|
||||
nmap ga <Plug>(EasyAlign)
|
||||
```
|
||||
|
||||
You can use either of the maps. Place the cursor on the paragraph and press
|
||||
|
||||
- `gaip` "(ga) start easy-align on (i)nner (p)aragraph"
|
||||
- or `vipga` "(v)isual-select (i)nner (p)aragraph and (ga) start easy-align"
|
||||
|
||||
To enable syntax highlighting in the code blocks, define and call the following
|
||||
function.
|
||||
|
||||
```vim
|
||||
function! GFM()
|
||||
let syntaxes = {
|
||||
\ 'ruby': 'syntax/ruby.vim',
|
||||
\ 'yaml': 'syntax/yaml.vim',
|
||||
\ 'vim': 'syntax/vim.vim',
|
||||
\ 'c': 'syntax/c.vim'
|
||||
\ }
|
||||
let langs = ['ruby', 'yaml', 'vim', 'c']
|
||||
|
||||
for [lang, syn] in items(syntaxes)
|
||||
for lang in langs
|
||||
unlet b:current_syntax
|
||||
silent! exec printf("syntax include @%s %s", lang, syn)
|
||||
silent! exec printf("syntax include @%s syntax/%s.vim", lang, lang)
|
||||
exec printf("syntax region %sSnip matchgroup=Snip start='```%s' end='```' contains=@%s",
|
||||
\ lang, lang, lang)
|
||||
endfor
|
||||
let b:current_syntax='mkd'
|
||||
|
||||
syntax sync fromstart
|
||||
endfunction
|
||||
```
|
||||
|
||||
Alignment around whitespaces
|
||||
----------------------------
|
||||
|
||||
You can align text around whitespaces with `<space>` delimiter key.
|
||||
|
||||
Start the interactive mode as described above (`gaip` or `vipga`) and try
|
||||
these commands:
|
||||
|
||||
- `<space>`
|
||||
- `2<space>`
|
||||
- `*<space>`
|
||||
- `-<space>`
|
||||
- `-2<space>`
|
||||
- `<Enter><space>`
|
||||
- `<Enter>*<space>`
|
||||
- `<Enter><Enter>*<space>`
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
|
||||
Paul McCartney 1942
|
||||
@@ -37,10 +65,21 @@ Pete Best 1941
|
||||
|
||||
```
|
||||
|
||||
|
||||
Formatting table
|
||||
----------------
|
||||
|
||||
Again, start the interactive mode and try these commands:
|
||||
|
||||
- `*|`
|
||||
- `**|`
|
||||
- `<Enter>*|`
|
||||
- `<Enter>**|`
|
||||
- `<Enter><Enter>*|`
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
|
||||
| Option| Type | Default | Description |
|
||||
|--|--|--|--|
|
||||
| threads | Fixnum | 1 | number of threads in the thread pool |
|
||||
@@ -51,10 +90,25 @@ Formatting table
|
||||
|batch_size | Fixnum | nil | number of maximum items to be assigned at once |
|
||||
|logger | Logger | nil | logger instance for debug logs |
|
||||
|
||||
```
|
||||
|
||||
|
||||
Alignment around =
|
||||
------------------
|
||||
|
||||
The default rule for delimiter key `=` aligns around a whole family of
|
||||
operators containing `=` character.
|
||||
|
||||
Try these commands in the interactive mode.
|
||||
|
||||
- `=`
|
||||
- `*=`
|
||||
- `**=`
|
||||
- `<Enter>**=`
|
||||
- `<Enter><Enter>*=`
|
||||
|
||||
### Example
|
||||
|
||||
```ruby
|
||||
|
||||
a =
|
||||
@@ -87,8 +141,10 @@ gg <=> ee
|
||||
Formatting YAML (or JSON)
|
||||
-------------------------
|
||||
|
||||
```yaml
|
||||
You can use `:`-rule here to align text around only the first occurrences of
|
||||
colons. In this case, you don't want to align around all the colons: `*:`.
|
||||
|
||||
```yaml
|
||||
mysql:
|
||||
# JDBC driver for MySQL database:
|
||||
driver: com.mysql.jdbc.Driver
|
||||
@@ -96,41 +152,265 @@ mysql:
|
||||
url: jdbc:mysql://localhost/test
|
||||
database: test
|
||||
"user:pass":r00t:pa55
|
||||
|
||||
```
|
||||
|
||||
Partial alignment in block-visual mode / Negative field index
|
||||
-------------------------------------------------------------
|
||||
Formatting multi-line method chaining
|
||||
-------------------------------------
|
||||
|
||||
Try `.` or `*.` on the following lines.
|
||||
|
||||
```ruby
|
||||
my_object
|
||||
.method1().chain()
|
||||
.second_method().call()
|
||||
.third().call()
|
||||
.method_4().execute()
|
||||
```
|
||||
|
||||
Notice that the indentation is adjusted to match the shortest one among those of
|
||||
the lines starting with the delimiter.
|
||||
|
||||
```ruby
|
||||
my_object
|
||||
.method1() .chain()
|
||||
.second_method().call()
|
||||
.third() .call()
|
||||
.method_4() .execute()
|
||||
```
|
||||
|
||||
|
||||
Using blockwise-visual mode or negative N-th parameter
|
||||
------------------------------------------------------
|
||||
|
||||
You can try either:
|
||||
- select text around `=>` in blockwise-visual mode (`CTRL-V`) and `ga=`
|
||||
- or `gaip-=`
|
||||
|
||||
```ruby
|
||||
options = { :caching => nil,
|
||||
:versions => 3,
|
||||
"cache=blocks" => false }.merge(options)
|
||||
|
||||
```
|
||||
|
||||
Commas
|
||||
------
|
||||
|
||||
```
|
||||
There is also a predefined rule for commas, try `*,`.
|
||||
|
||||
```
|
||||
aaa, bb,c
|
||||
d,eeeeeee
|
||||
fffff, gggggggggg,
|
||||
h, , ii
|
||||
j,,k
|
||||
|
||||
```
|
||||
|
||||
Ignoring delimiters in comments and strings
|
||||
-------------------------------------------
|
||||
Ignoring delimiters in comments or strings
|
||||
------------------------------------------
|
||||
|
||||
Delimiters highlighted as comments or strings are ignored by default, try
|
||||
`gaip*=` on the following lines.
|
||||
|
||||
```c
|
||||
|
||||
/* a */ b = c
|
||||
aa >= bb
|
||||
// aaa = bbb = cccc
|
||||
/* aaaa = */ bbbb === cccc " = dddd = " = eeee
|
||||
aaaaa /* bbbbb */ == ccccc /* != eeeee = */ === fffff
|
||||
|
||||
```
|
||||
|
||||
This only works when syntax highlighting is enabled.
|
||||
|
||||
Aligning in-line comments
|
||||
-------------------------
|
||||
|
||||
*Note: Since the current version provides '#'-rule as one of the default rules,
|
||||
you can ignore this section.*
|
||||
|
||||
```ruby
|
||||
apple = 1 # comment not aligned
|
||||
banana = 'Gros Michel' # comment 2
|
||||
```
|
||||
|
||||
So, how do we align the trailing comments in the above lines? Simply try
|
||||
`-<space>`. The spaces in the comments are ignored, so the trailing comment in
|
||||
each line is considered to be a single chunk.
|
||||
|
||||
But that doesn't work in the following case.
|
||||
|
||||
```ruby
|
||||
apple = 1 # comment not aligned
|
||||
apricot = 'DAD' + 'F#AD'
|
||||
banana = 'Gros Michel' # comment 2
|
||||
```
|
||||
|
||||
That is because the second line doesn't have trailing comment, and
|
||||
the last (`-`) space for that line is the one just before `'F#AD'`.
|
||||
|
||||
So, let's define a custom mapping for `#`.
|
||||
|
||||
```vim
|
||||
if !exists('g:easy_align_delimiters')
|
||||
let g:easy_align_delimiters = {}
|
||||
endif
|
||||
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }
|
||||
```
|
||||
|
||||
Notice that the rule overrides `ignore_groups` attribute in order *not to ignore*
|
||||
delimiters highlighted as comments.
|
||||
|
||||
Then on `#`, we get
|
||||
|
||||
```ruby
|
||||
apple = 1 # comment not aligned
|
||||
apricot = 'DAD' + 'F#AD'
|
||||
banana = 'string' # comment 2
|
||||
```
|
||||
|
||||
If you don't want to define the rule, you can do the same with the following
|
||||
command:
|
||||
|
||||
```vim
|
||||
" Using regular expression /#/
|
||||
" - "ig" is a shorthand notation of "ignore_groups"
|
||||
:EasyAlign/#/{'ig':['String']}
|
||||
|
||||
" Or more concisely with the shorthand notation;
|
||||
:EasyAlign/#/ig['String']
|
||||
```
|
||||
|
||||
In this case, the second line is ignored as it doesn't contain a `#` (The one
|
||||
in `'F#AD'` is ignored as it's highlighted as String). If you don't want the
|
||||
second line to be ignored, there are three options:
|
||||
|
||||
1. Set global `g:easy_align_ignore_unmatched` flag to 0
|
||||
2. Use `:EasyAlign` command with `ignore_unmatched` option
|
||||
3. Update the alignment rule with `ignore_unmatched` option
|
||||
|
||||
```vim
|
||||
" 1. Set global g:easy_align_ignore_unmatched to zero
|
||||
let g:easy_align_ignore_unmatched = 0
|
||||
|
||||
" 2. Using :EasyAlign command with ignore_unmatched option
|
||||
" 2-1. Using predefined rule with delimiter key #
|
||||
" - "iu" is expanded to "*i*gnore_*u*nmatched"
|
||||
:EasyAlign#{'iu':0}
|
||||
" or
|
||||
:EasyAlign#iu0
|
||||
|
||||
" 2-2. Using regular expression /#/
|
||||
:EasyAlign/#/ig['String']iu0
|
||||
|
||||
" 3. Update the alignment rule with ignore_unmatched option
|
||||
let g:easy_align_delimiters['#'] = {
|
||||
\ 'pattern': '#', 'ignore_groups': ['String'], 'ignore_unmatched': 0 }
|
||||
```
|
||||
|
||||
Then we get,
|
||||
|
||||
```ruby
|
||||
apple = 1 # comment not aligned
|
||||
apricot = 'DAD' + 'F#AD'
|
||||
banana = 'string' # comment 2
|
||||
```
|
||||
|
||||
Aligning C-style variable definition
|
||||
------------------------------------
|
||||
|
||||
Take the following example:
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
```
|
||||
|
||||
We can align these lines with the predefined `=` rule. Select the lines and
|
||||
press `ga=`
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
```
|
||||
|
||||
Not bad. However, the names of the variables, `str`, `count`, and `pi` are not
|
||||
aligned with each other. Can we do better? We can clearly see that simple
|
||||
`<space>`-rule won't properly align those names.
|
||||
So let's define an alignment rule than can handle this case.
|
||||
|
||||
```vim
|
||||
let g:easy_align_delimiters['d'] = {
|
||||
\ 'pattern': '\(const\|static\)\@<! ',
|
||||
\ 'left_margin': 0, 'right_margin': 0
|
||||
\ }
|
||||
```
|
||||
|
||||
This new rule aligns text around spaces that are *not* preceded by
|
||||
`const` or `static`. Let's select the lines and try `gad`.
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
```
|
||||
|
||||
Okay, the names are now aligned. We select the lines again with `gv`, and then
|
||||
press `ga=` to finish our alignment.
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
```
|
||||
|
||||
So far, so good. However, this rule is not sufficient to handle more complex
|
||||
cases involving C++ templates or Java generics. Take the following example:
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
static std::map<std::string, float>* scores = pointer;
|
||||
```
|
||||
|
||||
We see that our rule above doesn't work anymore.
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
static std::map<std::string, float>* scores = pointer;
|
||||
```
|
||||
|
||||
So what do we do? Let's try to improve our alignment rule.
|
||||
|
||||
```vim
|
||||
let g:easy_align_delimiters['d'] = {
|
||||
\ 'pattern': ' \ze\S\+\s*[;=]',
|
||||
\ 'left_margin': 0, 'right_margin': 0
|
||||
\ }
|
||||
```
|
||||
|
||||
Now the new rule has changed to align text around spaces that are followed
|
||||
by some non-whitespace characters and then an equals sign or a semi-colon.
|
||||
Try `vipgad`
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
static std::map<std::string, float>* scores = pointer;
|
||||
```
|
||||
|
||||
We're right on track, now press `gvga=` and voila!
|
||||
|
||||
```c
|
||||
const char* str = "Hello";
|
||||
int64_t count = 1 + 2;
|
||||
static double pi = 3.14;
|
||||
static std::map<std::string, float>* scores = pointer;
|
||||
```
|
||||
|
||||
|
||||
689
README.md
689
README.md
@@ -1,52 +1,148 @@
|
||||
vim-easy-align
|
||||
vim-easy-align 
|
||||
==============
|
||||
|
||||
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
||||
A simple, easy-to-use Vim alignment plugin.
|
||||
|
||||
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
|
||||
------------
|
||||
|
||||
Either [download zip file](http://www.vim.org/scripts/script.php?script_id=4520)
|
||||
and extract in ~/.vim or use [Vundle](https://github.com/gmarik/vundle) (recommended)
|
||||
or [Pathogen](https://github.com/tpope/vim-pathogen).
|
||||
Use your favorite plugin manager.
|
||||
|
||||
### With Vundle
|
||||
Using [vim-plug](https://github.com/junegunn/vim-plug):
|
||||
|
||||
```vim
|
||||
Bundle 'junegunn/vim-easy-align'
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
```
|
||||
|
||||
Quick start guide
|
||||
-----------------
|
||||
|
||||
Add the following mappings to your .vimrc.
|
||||
|
||||
```vim
|
||||
" Start interactive EasyAlign in visual mode (e.g. vipga)
|
||||
xmap ga <Plug>(EasyAlign)
|
||||
|
||||
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
|
||||
nmap ga <Plug>(EasyAlign)
|
||||
```
|
||||
|
||||
Then with the following lines of text,
|
||||
|
||||
```
|
||||
apple =red
|
||||
grass+=green
|
||||
sky-= blue
|
||||
```
|
||||
|
||||
try these commands:
|
||||
|
||||
- `vipga=`
|
||||
- `v`isual-select `i`nner `p`aragraph
|
||||
- Start EasyAlign command (`ga`)
|
||||
- Align around `=`
|
||||
- `gaip=`
|
||||
- Start EasyAlign command (`ga`) for `i`nner `p`aragraph
|
||||
- Align around `=`
|
||||
|
||||
Demo
|
||||
----
|
||||
|
||||
*Click on each image to see from the beginning.*
|
||||
|
||||
### Using predefined alignment rules
|
||||
|
||||
An *alignment rule* is a predefined set of options for common alignment tasks,
|
||||
which is identified by a single character, such as `<Space>`, `=`, `:`, `.`,
|
||||
`|`, `&`, `#`, and `,`.
|
||||
|
||||
#### `=`
|
||||
|
||||

|
||||
|
||||
- `=` Around the 1st occurrences
|
||||
- `2=` Around the 2nd occurrences
|
||||
- `*=` Around all occurrences
|
||||
- `**=` Left/Right alternating alignment around all occurrences
|
||||
- `<Enter>` Switching between left/right/center alignment modes
|
||||
|
||||
#### `<Space>`
|
||||
|
||||

|
||||
|
||||
- `<Space>` Around the 1st occurrences of whitespaces
|
||||
- `2<Space>` Around the 2nd occurrences
|
||||
- `-<Space>` Around the last occurrences
|
||||
- `<Enter><Enter>2<Space>` Center-alignment around the 2nd occurrences
|
||||
|
||||
#### `,`
|
||||
|
||||

|
||||
|
||||
- The predefined comma-rule places a comma right next to the preceding token
|
||||
without margin (`{'stick_to_left': 1, 'left_margin': 0}`)
|
||||
- You can change it with `<Right>` arrow
|
||||
|
||||
### Using regular expression
|
||||
|
||||

|
||||
|
||||
You can use an arbitrary regular expression by
|
||||
- pressing `<Ctrl-X>` in interactive mode
|
||||
- or using `:EasyAlign /REGEX/` command in visual mode or in normal mode with
|
||||
a range (e.g. `:%`)
|
||||
|
||||
### Different ways to start
|
||||
|
||||

|
||||
|
||||
This demo shows how you can start interactive mode with visual selection or use
|
||||
non-interactive `:EasyAlign` command.
|
||||
|
||||
### Aligning table cells
|
||||
|
||||

|
||||
|
||||
Check out various alignment options and "live interactive mode".
|
||||
|
||||
### Syntax-aware alignment
|
||||
|
||||

|
||||
|
||||
Delimiters in strings and comments are ignored by default.
|
||||
|
||||
### Using blockwise-visual mode
|
||||
|
||||

|
||||
|
||||
You can limit the scope with blockwise-visual mode.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
_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`.
|
||||
### Flow of execution
|
||||
|
||||
<img src="https://raw.githubusercontent.com/junegunn/i/master/easy-align/usage.png" width="469">
|
||||
|
||||
There are two ways to use easy-align.
|
||||
|
||||
#### 1. `<Plug>` mappings (interactive mode)
|
||||
|
||||
The recommended method is to use `<Plug>(EasyAlign)` mapping in normal and
|
||||
visual mode. They are usually mapped to `ga`, but you can choose any key
|
||||
sequences.
|
||||
|
||||
```vim
|
||||
vnoremap <silent> <Enter> :EasyAlign<cr>
|
||||
nmap ga <Plug>(EasyAlign)
|
||||
xmap ga <Plug>(EasyAlign)
|
||||
```
|
||||
|
||||
With the mapping, you can align selected lines with a few keystrokes.
|
||||
|
||||
1. `<Enter>` key to start interactive EasyAlign command
|
||||
1. Optional Enter keys to toggle right-justification mode
|
||||
1. Optional field number (default: 1)
|
||||
1. `ga` key in visual mode, or `ga` followed by a motion or a text
|
||||
object to start interactive mode
|
||||
1. (Optional) Enter keys to cycle between alignment mode (left, right, or center)
|
||||
1. (Optional) N-th delimiter (default: 1)
|
||||
- `1` Around the 1st occurrences of delimiters
|
||||
- `2` Around the 2nd occurrences of delimiters
|
||||
- ...
|
||||
@@ -55,35 +151,161 @@ With the mapping, you can align selected lines with a few keystrokes.
|
||||
- `-` Around the last occurrences of delimiters (`-1`)
|
||||
- `-2` Around the second to last occurrences of delimiters
|
||||
- ...
|
||||
1. Delimiter key (a single keystroke; `<space>`, `=`, `:`, `.`, `|`, `,`)
|
||||
1. Delimiter key (a single keystroke; `<Space>`, `=`, `:`, `.`, `|`, `&`, `#`, `,`) or an arbitrary regular expression followed by `<CTRL-X>`
|
||||
|
||||
Alignment rules for the following delimiters have been defined to meet the most needs.
|
||||
#### 2. Using `:EasyAlign` command
|
||||
|
||||
| Delimiter key | Description/Use cases |
|
||||
| ------------- | ---------------------------------------------------------- |
|
||||
| `<space>` | General alignment around spaces |
|
||||
| `=` | Operators containing equals sign (=, ==, !=, +=, &&=, ...) |
|
||||
| `:` | Suitable for formatting JSON or YAML |
|
||||
| `.` | Multi-line method chaining |
|
||||
| `,` | Multi-line method arguments |
|
||||
| | | Table markdown |
|
||||
If you prefer command-line, use `:EasyAlign` command instead.
|
||||
|
||||
### Example command sequences
|
||||
```vim
|
||||
" Using predefined rules
|
||||
:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
|
||||
|
||||
| With visual map | Description | Equivalent command |
|
||||
| ------------------- | -------------------------------------------------------- | ------------------------- |
|
||||
| `<Enter><space>` | Alignment around 1st whitespaces | `:'<,'>EasyAlign\ ` |
|
||||
| `<Enter>2<space>` | Alignment around 2nd whitespaces | `:'<,'>EasyAlign2\ ` |
|
||||
| `<Enter>-<space>` | Alignment around the last whitespaces | `:'<,'>EasyAlign-\ ` |
|
||||
| `<Enter>:` | Alignment around 1st colon | `:'<,'>EasyAlign:` |
|
||||
| `<Enter>=` | Alignment around 1st equals signs (and the likes) | `:'<,'>EasyAlign=` |
|
||||
| `<Enter>2=` | Alignment around 2nd equals signs (and the likes) | `:'<,'>EasyAlign2=` |
|
||||
| `<Enter>3=` | Alignment around 3rd equals signs (and the likes) | `:'<,'>EasyAlign3=` |
|
||||
| `<Enter>*=` | Alignment around all equals signs (and the likes) | `:'<,'>EasyAlign*=` |
|
||||
| `<Enter>**=` | Left-right alternating alignment around all equals signs | `:'<,'>EasyAlign**=` |
|
||||
| `<Enter><Enter>=` | Right-justified alignment around 1st equals signs | `:'<,'>EasyAlignRight=` |
|
||||
| `<Enter><Enter>**=` | Right-left alternating alignment around all equals signs | `:'<,'>EasyAlignRight**=` |
|
||||
| ... | ... | |
|
||||
" Using regular expression
|
||||
:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
|
||||
```
|
||||
|
||||
### Regular expression vs. predefined rules
|
||||
|
||||
You can use regular expressions but it's usually much easier to use predefined
|
||||
alignment rules that you can trigger with a single keystroke.
|
||||
|
||||
| Key | Description/Use cases |
|
||||
| --------- | -------------------------------------------------------------------- |
|
||||
| `<Space>` | General alignment around whitespaces |
|
||||
| `=` | Operators containing equals sign (`=`, `==,` `!=`, `+=`, `&&=`, ...) |
|
||||
| `:` | Suitable for formatting JSON or YAML |
|
||||
| `.` | Multi-line method chaining |
|
||||
| `,` | Multi-line method arguments |
|
||||
| `&` | LaTeX tables (matches `&` and `\\`) |
|
||||
| `#` | Ruby/Python comments |
|
||||
| `"` | Vim comments |
|
||||
| `<Bar>` | Table markdown |
|
||||
|
||||
You can also define your own rules with `g:easy_align_delimiters` which will
|
||||
be described in [the later section](#extending-alignment-rules).
|
||||
|
||||
----
|
||||
|
||||
### Interactive mode
|
||||
|
||||
Interactive mode is started either with `<Plug>(EasyAlign)` mapping or with
|
||||
`:EasyAlign` command with no argument.
|
||||
|
||||
#### Examples using predefined rules
|
||||
|
||||
| Keystrokes | Description | Equivalent command |
|
||||
| ------------ | ---------------------------------- | --------------------- |
|
||||
| `<Space>` | Around 1st whitespaces | `:'<,'>EasyAlign\ ` |
|
||||
| `2<Space>` | Around 2nd whitespaces | `:'<,'>EasyAlign2\ ` |
|
||||
| `-<Space>` | Around the last whitespaces | `:'<,'>EasyAlign-\ ` |
|
||||
| `-2<Space>` | Around the 2nd to last whitespaces | `:'<,'>EasyAlign-2\ ` |
|
||||
| `:` | Around 1st colon (`key: value`) | `:'<,'>EasyAlign:` |
|
||||
| `<Right>:` | Around 1st colon (`key : value`) | `:'<,'>EasyAlign:>l1` |
|
||||
| `=` | Around 1st operators with = | `:'<,'>EasyAlign=` |
|
||||
| `3=` | Around 3rd operators with = | `:'<,'>EasyAlign3=` |
|
||||
| `*=` | Around all operators with = | `:'<,'>EasyAlign*=` |
|
||||
| `**=` | Left-right alternating around = | `:'<,'>EasyAlign**=` |
|
||||
| `<Enter>=` | Right alignment around 1st = | `:'<,'>EasyAlign!=` |
|
||||
| `<Enter>**=` | Right-left alternating around = | `:'<,'>EasyAlign!**=` |
|
||||
|
||||
Instead of finishing the alignment with a delimiter key, you can type in
|
||||
a regular expression if you press `<CTRL-/>` or `<CTRL-X>`.
|
||||
|
||||
#### Alignment options in interactive mode
|
||||
|
||||
While in interactive mode, you can set alignment options using special shortcut
|
||||
keys listed below. The meaning of each option will be described in
|
||||
[the following sections](#alignment-options).
|
||||
|
||||
| Key | Option | Values |
|
||||
| --------- | ------------------ | -------------------------------------------------- |
|
||||
| `CTRL-F` | `filter` | Input string (`[gv]/.*/?`) |
|
||||
| `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']` |
|
||||
| `CTRL-A` | `align` | Input string (`/[lrc]+\*{0,2}/`) |
|
||||
| `<Left>` | `stick_to_left` | `{ 'stick_to_left': 1, 'left_margin': 0 }` |
|
||||
| `<Right>` | `stick_to_left` | `{ 'stick_to_left': 0, 'left_margin': 1 }` |
|
||||
| `<Down>` | `*_margin` | `{ 'left_margin': 0, 'right_margin': 0 }` |
|
||||
|
||||
#### Live interactive mode
|
||||
|
||||
If you're performing a complex alignment where multiple options should be
|
||||
carefully adjusted, try "live interactive mode" where you can preview the result
|
||||
of the alignment on-the-fly as you type in.
|
||||
|
||||
Live interactive mode can be started with either `<Plug>(LiveEasyAlign)` map
|
||||
or `:LiveEasyAlign` command. Or you can switch to live interactive mode while
|
||||
in ordinary interactive mode by pressing `<CTRL-P>`. (P for Preview)
|
||||
|
||||
In live interactive mode, you have to type in the same delimiter (or
|
||||
`<CTRL-X>` on regular expression) again to finalize the alignment. This allows
|
||||
you to preview the result of the alignment and freely change the delimiter
|
||||
using backspace key without leaving the interactive mode.
|
||||
|
||||
### :EasyAlign command
|
||||
|
||||
Instead of starting interactive mode, you can use non-interactive `:EasyAlign`
|
||||
command.
|
||||
|
||||
```vim
|
||||
" Using predefined alignment rules
|
||||
" :EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
|
||||
:EasyAlign :
|
||||
:EasyAlign =
|
||||
:EasyAlign *=
|
||||
:EasyAlign 3\
|
||||
|
||||
" Using arbitrary regular expressions
|
||||
" :EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
|
||||
:EasyAlign /[:;]\+/
|
||||
:EasyAlign 2/[:;]\+/
|
||||
:EasyAlign */[:;]\+/
|
||||
:EasyAlign **/[:;]\+/
|
||||
```
|
||||
|
||||
A command can end with alignment options, [each of which will be discussed in
|
||||
detail later](#alignment-options), in Vim dictionary format.
|
||||
|
||||
- `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': 0 }`
|
||||
|
||||
`stick_to_left` of 1 means that the matched delimiter should be positioned right
|
||||
next to the preceding token, and `left_margin` of 0 removes the margin on the
|
||||
left. So we get:
|
||||
|
||||
apple;: banana:: cake
|
||||
data;; exchange:; format
|
||||
|
||||
You don't have to write complete names as long as they're distinguishable.
|
||||
|
||||
- `:EasyAlign * /[:;]\+/ { 'stl': 1, 'l': 0 }`
|
||||
|
||||
You can even omit spaces between the arguments.
|
||||
|
||||
- `:EasyAlign*/[:;]\+/{'s':1,'l':0}`
|
||||
|
||||
Nice. But let's make it even shorter. Option values can be written in shorthand
|
||||
notation.
|
||||
|
||||
- `:EasyAlign*/[:;]\+/<l0`
|
||||
|
||||
The following table summarizes the shorthand notation.
|
||||
|
||||
| Option | Expression |
|
||||
| ------------------ | -------------- |
|
||||
| `filter` | `[gv]/.*/` |
|
||||
| `left_margin` | `l[0-9]+` |
|
||||
| `right_margin` | `r[0-9]+` |
|
||||
| `stick_to_left` | `<` or `>` |
|
||||
| `ignore_unmatched` | `iu[01]` |
|
||||
| `ignore_groups` | `ig\[.*\]` |
|
||||
| `align` | `a[lrc*]*` |
|
||||
| `delimiter_align` | `d[lrc]` |
|
||||
| `indentation` | `i[ksdn]` |
|
||||
|
||||
### Partial alignment in blockwise-visual mode
|
||||
|
||||
@@ -110,16 +332,70 @@ my_hash = { :a => 1,
|
||||
```
|
||||
|
||||
However, in this case, we don't really need blockwise visual mode
|
||||
since the same can be easily done using the negative field number: `<Enter>-=`
|
||||
since the same can be easily done using the negative N-th parameter: `<Enter>-=`
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| ----------------------------- | ---------- | --------------------- | -------------------------------------------------- |
|
||||
| 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_delimiters | dictionary | `{}` | Extend or override alignment rules |
|
||||
Alignment options
|
||||
-----------------
|
||||
|
||||
### List of options
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| ------------------ | ------- | --------------------- | ------------------------------------------------------- |
|
||||
| `filter` | string | | Line filtering expression: `g/../` or `v/../` |
|
||||
| `left_margin` | number | 1 | Number of spaces to attach before delimiter |
|
||||
| `left_margin` | string | `' '` | String to attach before delimiter |
|
||||
| `right_margin` | number | 1 | Number of spaces to attach after delimiter |
|
||||
| `right_margin` | string | `' '` | String to attach after delimiter |
|
||||
| `stick_to_left` | boolean | 0 | Whether to position delimiter on the left-side |
|
||||
| `ignore_groups` | list | ['String', 'Comment'] | Delimiters in these syntax highlight groups are ignored |
|
||||
| `ignore_unmatched` | boolean | 1 | Whether to ignore lines without matching delimiter |
|
||||
| `indentation` | string | `k` | Indentation method (*k*eep, *d*eep, *s*hallow, *n*one) |
|
||||
| `delimiter_align` | string | `r` | Determines how to align delimiters of different lengths |
|
||||
| `align` | string | `l` | Alignment modes for multiple occurrences of delimiters |
|
||||
|
||||
There are 4 ways to set alignment options (from lowest precedence to highest):
|
||||
|
||||
1. Some option values can be set with corresponding global variables
|
||||
2. Option values can be specified in the definition of each alignment rule
|
||||
3. Option values can be given as arguments to `:EasyAlign` command
|
||||
4. Option values can be set in interactive mode using special shortcut keys
|
||||
|
||||
| Option name | Shortcut key | Abbreviated | Global variable |
|
||||
| ------------------ | ------------------- | -------------- | ------------------------------- |
|
||||
| `filter` | `CTRL-F` | `[gv]/.*/` | |
|
||||
| `left_margin` | `CTRL-L` | `l[0-9]+` | |
|
||||
| `right_margin` | `CTRL-R` | `r[0-9]+` | |
|
||||
| `stick_to_left` | `<Left>`, `<Right>` | `<` or `>` | |
|
||||
| `ignore_groups` | `CTRL-G` | `ig\[.*\]` | `g:easy_align_ignore_groups` |
|
||||
| `ignore_unmatched` | `CTRL-U` | `iu[01]` | `g:easy_align_ignore_unmatched` |
|
||||
| `indentation` | `CTRL-I` | `i[ksdn]` | `g:easy_align_indentation` |
|
||||
| `delimiter_align` | `CTRL-D` | `d[lrc]` | `g:easy_align_delimiter_align` |
|
||||
| `align` | `CTRL-A` | `a[lrc*]*` | |
|
||||
|
||||
### Filtering lines
|
||||
|
||||
With `filter` option, you can align lines that only match or do not match a
|
||||
given pattern. There are several ways to set the pattern.
|
||||
|
||||
1. Press `CTRL-F` in interactive mode and type in `g/pat/` or `v/pat/`
|
||||
2. In command-line, it can be written in dictionary format: `{'filter': 'g/pat/'}`
|
||||
3. Or in shorthand notation: `g/pat/` or `v/pat/`
|
||||
|
||||
(You don't need to escape '/'s in the regular expression)
|
||||
|
||||
#### Examples
|
||||
|
||||
```vim
|
||||
" Start interactive mode with filter option set to g/hello/
|
||||
EasyAlign g/hello/
|
||||
|
||||
" Start live interactive mode with filter option set to v/goodbye/
|
||||
LiveEasyAlign v/goodbye/
|
||||
|
||||
" Align the lines with 'hi' around the first colons
|
||||
EasyAlign:g/hi/
|
||||
```
|
||||
|
||||
### Ignoring delimiters in comments or strings
|
||||
|
||||
@@ -130,8 +406,8 @@ highlighted as code comments or strings are ignored.
|
||||
```vim
|
||||
" 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']
|
||||
" any of the following regular expressions, it will be ignored.
|
||||
let g:easy_align_ignore_groups = ['Comment', 'String']
|
||||
```
|
||||
|
||||
For example, the following paragraph
|
||||
@@ -147,7 +423,7 @@ For example, the following paragraph
|
||||
}
|
||||
```
|
||||
|
||||
becomes as follows on `<Enter>:`
|
||||
becomes as follows on `<Enter>:` (or `:EasyAlign:`)
|
||||
|
||||
```ruby
|
||||
{
|
||||
@@ -162,14 +438,15 @@ becomes as follows on `<Enter>:`
|
||||
|
||||
Naturally, this feature only works when syntax highlighting is enabled.
|
||||
|
||||
You can change the default rule by defining `g:easy_align_ignores` array.
|
||||
You can change the default rule by using one of these 4 methods.
|
||||
|
||||
```vim
|
||||
" Ignore nothing!
|
||||
let g:easy_align_ignores = []
|
||||
```
|
||||
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:ig[]`
|
||||
|
||||
Then you get,
|
||||
For example if you set `ignore_groups` option to be an empty list, you get
|
||||
|
||||
```ruby
|
||||
{
|
||||
@@ -182,14 +459,37 @@ Then you get,
|
||||
}
|
||||
```
|
||||
|
||||
Satisfied? :satisfied:
|
||||
If a pattern in `ignore_groups` is prepended by a `!`, it will have the opposite
|
||||
meaning. For instance, if `ignore_groups` is given as `['!Comment']`, delimiters
|
||||
that are *not* highlighted as Comment will be ignored during the alignment.
|
||||
|
||||
To make `ignore_groups` work, and to debug the related issues, it is useful to
|
||||
know which highlight group a certain location in a file belongs to. A special
|
||||
function exists for this purpose, returning exactly the name of the highlight
|
||||
group that is used by the easy align plugin.
|
||||
|
||||
```vim
|
||||
" Highlight group name of the cursor position
|
||||
echo easy_align#get_highlight_group_name()
|
||||
|
||||
" Highlight group name of the line 10, column 20
|
||||
echo easy_align#get_highlight_group_name(10, 20)
|
||||
```
|
||||
|
||||
### Ignoring unmatched lines
|
||||
|
||||
Lines without any matching delimiter are ignored as well (except in
|
||||
right-justification mode).
|
||||
`ignore_unmatched` option determines how EasyAlign command processes lines that
|
||||
do not have N-th delimiter.
|
||||
|
||||
For example, when aligning the following code block around the colons,
|
||||
1. In left-alignment mode, they are ignored
|
||||
2. In right or center-alignment mode, they are *not* ignored, and the last
|
||||
tokens from those lines are aligned as well as if there is an invisible
|
||||
trailing delimiter at the end of each line
|
||||
3. If `ignore_unmatched` is 1, they are ignored regardless of the alignment mode
|
||||
4. If `ignore_unmatched` is 0, they are *not* ignored regardless of the mode
|
||||
|
||||
Let's take an example.
|
||||
When we align the following code block around the (1st) colons,
|
||||
|
||||
```ruby
|
||||
{
|
||||
@@ -213,11 +513,13 @@ this is usually what we want.
|
||||
}
|
||||
```
|
||||
|
||||
However, this default behavior is also configurable.
|
||||
However, we can override this default behavior by setting `ignore_unmatched`
|
||||
option to zero using one of the following methods.
|
||||
|
||||
```vim
|
||||
let g:easy_align_ignore_unmatched = 0
|
||||
```
|
||||
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:iu0`
|
||||
|
||||
Then we get,
|
||||
|
||||
@@ -231,29 +533,238 @@ Then we get,
|
||||
}
|
||||
```
|
||||
|
||||
### Extending alignment rules
|
||||
### Aligning delimiters of different lengths
|
||||
|
||||
Global `g:easy_align_delimiter_align` option and rule-wise/command-wise
|
||||
`delimiter_align` option determines how matched delimiters of different lengths
|
||||
are aligned.
|
||||
|
||||
```ruby
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
```
|
||||
|
||||
By default, delimiters are right-aligned as follows.
|
||||
|
||||
```ruby
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
```
|
||||
|
||||
However, with `:EasyAlign=dl`, delimiters are left-aligned.
|
||||
|
||||
```ruby
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
```
|
||||
|
||||
And on `:EasyAlign=dc`, center-aligned.
|
||||
|
||||
```ruby
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
```
|
||||
|
||||
In interactive mode, you can change the option value with `CTRL-D` key.
|
||||
|
||||
### Adjusting indentation
|
||||
|
||||
By default :EasyAlign command keeps the original indentation of the lines. But
|
||||
then again we have `indentation` option. See the following example.
|
||||
|
||||
```ruby
|
||||
# Lines with different indentation
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Default: _k_eep the original indentation
|
||||
# :EasyAlign=
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Use the _s_hallowest indentation among the lines
|
||||
# :EasyAlign=is
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Use the _d_eepest indentation among the lines
|
||||
# :EasyAlign=id
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Indentation: _n_one
|
||||
# :EasyAlign=in
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
```
|
||||
|
||||
In interactive mode, you can change the option value with `CTRL-I` key.
|
||||
|
||||
### Alignments over multiple occurrences of delimiters
|
||||
|
||||
As stated above, "N-th" parameter is used to target specific occurrences of
|
||||
the delimiter when it appears multiple times in each line.
|
||||
|
||||
To recap:
|
||||
|
||||
```vim
|
||||
" Left-alignment around the FIRST occurrences of delimiters
|
||||
:EasyAlign =
|
||||
|
||||
" Left-alignment around the SECOND occurrences of delimiters
|
||||
:EasyAlign 2=
|
||||
|
||||
" Left-alignment around the LAST occurrences of delimiters
|
||||
:EasyAlign -=
|
||||
|
||||
" Left-alignment around ALL occurrences of delimiters
|
||||
:EasyAlign *=
|
||||
|
||||
" Left-right ALTERNATING alignment around all occurrences of delimiters
|
||||
:EasyAlign **=
|
||||
|
||||
" Right-left ALTERNATING alignment around all occurrences of delimiters
|
||||
:EasyAlign! **=
|
||||
```
|
||||
|
||||
In addition to these, you can fine-tune alignments over multiple occurrences
|
||||
of the delimiters with 'align' option. (The option can also be set in
|
||||
interactive mode with the special key `CTRL-A`)
|
||||
|
||||
```vim
|
||||
" Left alignment over the first two occurrences of delimiters
|
||||
:EasyAlign = { 'align': 'll' }
|
||||
|
||||
" Right, left, center alignment over the 1st to 3rd occurrences of delimiters
|
||||
:EasyAlign = { 'a': 'rlc' }
|
||||
|
||||
" Using shorthand notation
|
||||
:EasyAlign = arlc
|
||||
|
||||
" Right, left, center alignment over the 2nd to 4th occurrences of delimiters
|
||||
:EasyAlign 2=arlc
|
||||
|
||||
" (*) Repeating alignments (default: l, r, or c)
|
||||
" Right, left, center, center, center, center, ...
|
||||
:EasyAlign *=arlc
|
||||
|
||||
" (**) Alternating alignments (default: lr or rl)
|
||||
" Right, left, center, right, left, center, ...
|
||||
:EasyAlign **=arlc
|
||||
|
||||
" Right, left, center, center, center, ... repeating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3=arlc*
|
||||
|
||||
" Right, left, center, right, left, center, ... alternating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3=arlc**
|
||||
```
|
||||
|
||||
### Extending alignment rules
|
||||
|
||||
Although the default rules should cover the most of the use cases,
|
||||
you can extend the rules by setting a dictionary named `g:easy_align_delimiters`.
|
||||
|
||||
You may refer to the definitions of the default alignment rules
|
||||
[here](https://github.com/junegunn/vim-easy-align/blob/2.9.6/autoload/easy_align.vim#L32-L46).
|
||||
|
||||
#### Examples
|
||||
|
||||
```vim
|
||||
" Examples
|
||||
let g:easy_align_delimiters = {
|
||||
\ '>': { 'pattern': '>>\|=>\|>' },
|
||||
\ '/': { 'pattern': '//\+\|/\*\|\*/' },
|
||||
\ '#': { 'pattern': '#\+' },
|
||||
\ '/': {
|
||||
\ 'pattern': '//\+\|/\*\|\*/',
|
||||
\ 'delimiter_align': 'l',
|
||||
\ 'ignore_groups': ['!Comment'] },
|
||||
\ ']': {
|
||||
\ 'pattern': '[\[\]]',
|
||||
\ 'margin_left': '',
|
||||
\ 'margin_right': '',
|
||||
\ 'pattern': '[[\]]',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0,
|
||||
\ 'stick_to_left': 0
|
||||
\ },
|
||||
\ ')': {
|
||||
\ 'pattern': '[()]',
|
||||
\ 'margin_left': '',
|
||||
\ 'margin_right': '',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0,
|
||||
\ 'stick_to_left': 0
|
||||
\ },
|
||||
\ 'd': {
|
||||
\ 'pattern': ' \(\S\+\s*[;=]\)\@=',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0
|
||||
\ }
|
||||
\ }
|
||||
```
|
||||
|
||||
Other options
|
||||
-------------
|
||||
|
||||
### Disabling &foldmethod during alignment
|
||||
|
||||
[It is reported](https://github.com/junegunn/vim-easy-align/issues/14) that
|
||||
`&foldmethod` value of `expr` or `syntax` can significantly slow down the
|
||||
alignment when editing a large, complex file with many folds. To alleviate this
|
||||
issue, EasyAlign provides an option to temporarily set `&foldmethod` to `manual`
|
||||
during the alignment task. In order to enable this feature, set
|
||||
`g:easy_align_bypass_fold` switch to 1.
|
||||
|
||||
```vim
|
||||
let g:easy_align_bypass_fold = 1
|
||||
```
|
||||
|
||||
### Left/right/center mode switch in interactive mode
|
||||
|
||||
In interactive mode, you can choose the alignment mode you want by pressing
|
||||
enter keys. The non-bang command, `:EasyAlign` starts in left-alignment mode
|
||||
and changes to right and center mode as you press enter keys, while the bang
|
||||
version first starts in right-alignment mode.
|
||||
|
||||
- `:EasyAlign`
|
||||
- Left, Right, Center
|
||||
- `:EasyAlign!`
|
||||
- Right, Left, Center
|
||||
|
||||
If you do not prefer this default mode transition, you can define your own
|
||||
settings as follows.
|
||||
|
||||
```vim
|
||||
let g:easy_align_interactive_modes = ['l', 'r']
|
||||
let g:easy_align_bang_interactive_modes = ['c', 'r']
|
||||
```
|
||||
|
||||
Advanced examples and use cases
|
||||
-------------------------------
|
||||
|
||||
See [EXAMPLES.md](https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md)
|
||||
for more examples.
|
||||
|
||||
Related work
|
||||
------------
|
||||
|
||||
- [DrChip's Alignment Tool for Vim](http://www.drchip.org/astronaut/vim/align.html)
|
||||
- [Tabular](https://github.com/godlygeek/tabular)
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,86 +1,527 @@
|
||||
vim-easy-align *vim-easy-align* *easy-align*
|
||||
=========================================================================
|
||||
*easy-align.txt* easy-align Last change: December 14 2014
|
||||
EASY-ALIGN - TABLE OF CONTENTS *easyalign* *easy-align* *easy-align-toc*
|
||||
==============================================================================
|
||||
|
||||
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
||||
|
||||
Author: Junegunn Choi
|
||||
Source: https://github.com/junegunn/vim-easy-align
|
||||
vim-easy-align
|
||||
Demo |easy-align-1|
|
||||
Features |easy-align-2|
|
||||
Installation |easy-align-3|
|
||||
TLDR - One-minute guide |easy-align-4|
|
||||
Usage |easy-align-5|
|
||||
Concept of alignment rule |easy-align-5-1|
|
||||
Execution models |easy-align-5-2|
|
||||
1. Using <Plug> mappings |easy-align-5-2-1|
|
||||
2. Using :EasyAlign command |easy-align-5-2-2|
|
||||
Interactive mode |easy-align-5-3|
|
||||
Predefined alignment rules |easy-align-5-3-1|
|
||||
Examples |easy-align-5-3-2|
|
||||
Using regular expressions |easy-align-5-3-3|
|
||||
Alignment options in interactive mode |easy-align-5-3-4|
|
||||
Live interactive mode |easy-align-5-4|
|
||||
Non-interactive mode |easy-align-5-5|
|
||||
Partial alignment in blockwise-visual mode |easy-align-5-6|
|
||||
Alignment options |easy-align-6|
|
||||
List of options |easy-align-6-1|
|
||||
Filtering lines |easy-align-6-2|
|
||||
Examples |easy-align-6-2-1|
|
||||
Ignoring delimiters in comments or strings |easy-align-6-3|
|
||||
Ignoring unmatched lines |easy-align-6-4|
|
||||
Aligning delimiters of different lengths |easy-align-6-5|
|
||||
Adjusting indentation |easy-align-6-6|
|
||||
Alignments over multiple occurrences of delimiters |easy-align-6-7|
|
||||
Extending alignment rules |easy-align-6-8|
|
||||
Examples |easy-align-6-8-1|
|
||||
Other options |easy-align-7|
|
||||
Disabling &foldmethod during alignment |easy-align-7-1|
|
||||
Left/right/center mode switch in interactive mode |easy-align-7-2|
|
||||
Advanced examples and use cases |easy-align-8|
|
||||
Related work |easy-align-9|
|
||||
Author |easy-align-10|
|
||||
License |easy-align-11|
|
||||
|
||||
|
||||
EasyAlign *EasyAlign*
|
||||
-------------------------------------------------------------------------
|
||||
VIM-EASY-ALIGN *vim-easy-align*
|
||||
==============================================================================
|
||||
|
||||
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`.
|
||||
|
||||
vnoremap <silent> <Enter> :EasyAlign<cr>
|
||||
|
||||
With this mapping, you can align selected lines with a few keystrokes.
|
||||
|
||||
1. <Enter> key to start interactive EasyAlign command
|
||||
2. Optional Enter keys to switch justficiation mode (default: left)
|
||||
3. Optional field number (default: 1)
|
||||
1 Around the 1st occurrences of delimiters
|
||||
2 Around the 2nd occurrences of delimiters
|
||||
* Around all occurrences of delimiters
|
||||
** Left-right alternating alignment around all delimiters
|
||||
- Around the last occurrences of delimiters (`-1`)
|
||||
-2 Around the second to last occurrences of delimiters
|
||||
...
|
||||
4. Delimiter key (a single keystroke)
|
||||
<space> General alignment around whitespaces
|
||||
= Operators containing equals sign (=, ==, !=, +=, &&=, ...)
|
||||
: Suitable for formatting JSON or YAML
|
||||
. Multi-line method chaining
|
||||
, Multi-line method arguments. CSV.
|
||||
| Table markdown
|
||||
|
||||
During the key sequence, <Enter> key will toggle right-justification mode.
|
||||
|
||||
Examples:
|
||||
|
||||
<Enter><space> Alignment around 1st whitespaces
|
||||
<Enter>2<space> Alignment around 2nd whitespaces
|
||||
<Enter>-<space> Alignment around the last whitespaces
|
||||
<Enter>: Alignment around 1st colon
|
||||
<Enter>= Alignment around 1st equals signs (and the likes)
|
||||
<Enter>2= Alignment around 2nd equals signs (and the likes)
|
||||
<Enter>3= Alignment around 3rd equals signs (and the likes)
|
||||
<Enter>*= Alignment around all equals signs (and the likes)
|
||||
<Enter>**= Left-right alternating alignment around all equals signs
|
||||
<Enter><Enter>= Right-justified alignment around 1st equals signs
|
||||
<Enter><Enter>**= Right-left alternating alignment around all equals signs
|
||||
A simple, easy-to-use Vim alignment plugin.
|
||||
|
||||
|
||||
EasyAlignRight *EasyAlignRight*
|
||||
-------------------------------------------------------------------------
|
||||
*easy-align-1*
|
||||
DEMO *easy-align-demo*
|
||||
==============================================================================
|
||||
|
||||
EasyAlignRight is the right-justified version of EasyAlign command.
|
||||
Screencast:
|
||||
https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align.gif
|
||||
|
||||
(Too fast? Slower GIF is {here}{1})
|
||||
|
||||
{1} https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align-slow.gif
|
||||
|
||||
|
||||
Partial alignment in blockwise-visual mode
|
||||
-------------------------------------------------------------------------
|
||||
*easy-align-2*
|
||||
FEATURES *easy-align-features*
|
||||
==============================================================================
|
||||
|
||||
In blockwise-visual mode (`CTRL-V`), EasyAlign command aligns only
|
||||
the selected text in the block, instead of the whole lines in the range.
|
||||
- Easy to use
|
||||
- Comes with a predefined set of alignment rules
|
||||
- Provides a fast and intuitive interface
|
||||
- Extensible
|
||||
- You can define your own rules
|
||||
- Supports arbitrary regular expressions
|
||||
- Optimized for code editing
|
||||
- Takes advantage of syntax highlighting feature to avoid unwanted
|
||||
alignments
|
||||
|
||||
|
||||
Ignoring delimiters in comments or strings *g:easy_align_ignores*
|
||||
-------------------------------------------------------------------------
|
||||
*easy-align-3*
|
||||
INSTALLATION *easy-align-installation*
|
||||
==============================================================================
|
||||
|
||||
EasyAlign can be configured to ignore delimiters in certain syntax
|
||||
highlight groups, such as code comments or strings. By default, delimiters
|
||||
that are highlighted as code comments or strings are ignored.
|
||||
Use your favorite plugin manager.
|
||||
|
||||
Using {vim-plug}{2}:
|
||||
>
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
<
|
||||
{2} https://github.com/junegunn/vim-plug
|
||||
|
||||
|
||||
*easy-align-4*
|
||||
TLDR - ONE-MINUTE GUIDE *easy-align-tldr-one-minute-guide*
|
||||
==============================================================================
|
||||
|
||||
Add the following mappings to your .vimrc.
|
||||
|
||||
*<Plug>(EasyAlign)*
|
||||
>
|
||||
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
|
||||
vmap <Enter> <Plug>(EasyAlign)
|
||||
|
||||
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
|
||||
nmap ga <Plug>(EasyAlign)
|
||||
<
|
||||
And with the following lines of text,
|
||||
>
|
||||
apple =red
|
||||
grass+=green
|
||||
sky-= blue
|
||||
<
|
||||
try these commands:
|
||||
|
||||
- vip<Enter>=
|
||||
- `v`isual-select `i`nner `p`aragraph
|
||||
- Start EasyAlign command (<Enter>)
|
||||
- Align around `=`
|
||||
- `gaip=`
|
||||
- Start EasyAlign command (`ga`) for `i`nner `p`aragraph
|
||||
- Align around `=`
|
||||
|
||||
Notice that the commands are repeatable with `.` key if you have installed
|
||||
{repeat.vim}{3}. Install {visualrepeat}{4} as well if you want to repeat in
|
||||
visual mode.
|
||||
|
||||
{3} https://github.com/tpope/vim-repeat
|
||||
{4} https://github.com/vim-scripts/visualrepeat
|
||||
|
||||
|
||||
*easy-align-5*
|
||||
USAGE *easy-align-usage*
|
||||
==============================================================================
|
||||
|
||||
|
||||
< Concept of alignment rule >_________________________________________________~
|
||||
*easy-align-concept-of-alignment-rule*
|
||||
*easy-align-5-1*
|
||||
|
||||
Though easy-align can align lines of text around any delimiter, it provides
|
||||
shortcuts for the most common use cases with the concept of "alignment rule".
|
||||
|
||||
An alignment rule is a predefined set of options for common alignment tasks,
|
||||
which is identified by a single character, DELIMITER KEY, such as <Space>,
|
||||
`=`, `:`, `.`, `|`, `&`, `#`, and `,`.
|
||||
|
||||
Think of it as a shortcut. Instead of writing regular expression and setting
|
||||
several options, you can just type in a single character.
|
||||
|
||||
|
||||
< Execution models >__________________________________________________________~
|
||||
*easy-align-execution-models*
|
||||
*easy-align-5-2*
|
||||
|
||||
There are two ways to use easy-align.
|
||||
|
||||
|
||||
1. Using <Plug> mappings~
|
||||
*easy-align-1-using-plug-mappings*
|
||||
*easy-align-5-2-1*
|
||||
|
||||
The recommended method is to use <Plug> mappings as described earlier.
|
||||
|
||||
*<Plug>(LiveEasyAlign)*
|
||||
|
||||
----------------------+--------+-----------------------------------------------------
|
||||
Mapping | Mode | Description ~
|
||||
----------------------+--------+-----------------------------------------------------
|
||||
<Plug>(EasyAlign) | normal | Start interactive mode for a motion/text object
|
||||
<Plug>(EasyAlign) | visual | Start interactive mode for the selection
|
||||
<Plug>(LiveEasyAlign) | normal | Start live-interactive mode for a motion/text object
|
||||
<Plug>(LiveEasyAlign) | visual | Start live-interactive mode for the selection
|
||||
----------------------+--------+-----------------------------------------------------
|
||||
|
||||
|
||||
2. Using :EasyAlign command~
|
||||
*easy-align-2-using-easyalign-command*
|
||||
*easy-align-5-2-2*
|
||||
|
||||
*:EasyAlign*
|
||||
|
||||
If you prefer command-line or do not want to start interactive mode, you can
|
||||
use `:EasyAlign` command instead.
|
||||
|
||||
*:LiveEasyAlign*
|
||||
|
||||
-------------------------------------------+-----------------------------------------------
|
||||
Mode | Command ~
|
||||
-------------------------------------------+-----------------------------------------------
|
||||
Interactive mode | `:EasyAlign[!] [OPTIONS]`
|
||||
Live interactive mode | `:LiveEasyAlign[!] [...]`
|
||||
Non-interactive mode (predefined rules) | `:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]`
|
||||
Non-interactive mode (regular expressions) | `:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]`
|
||||
-------------------------------------------+-----------------------------------------------
|
||||
|
||||
|
||||
< Interactive mode >__________________________________________________________~
|
||||
*easy-align-interactive-mode*
|
||||
*easy-align-5-3*
|
||||
|
||||
The following sections will assume that you have <Plug>(EasyAlign) mappings in
|
||||
your .vimrc as below:
|
||||
>
|
||||
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
|
||||
vmap <Enter> <Plug>(EasyAlign)
|
||||
|
||||
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
|
||||
nmap ga <Plug>(EasyAlign)
|
||||
<
|
||||
With these mappings, you can align text with only a few keystrokes.
|
||||
|
||||
1. <Enter> key in visual mode, or `ga` followed by a motion or a text object to
|
||||
start interactive mode
|
||||
2. Optional: Enter keys to select alignment mode (left, right, or center)
|
||||
3. Optional: N-th delimiter (default: 1)
|
||||
- `1` Around the 1st occurrences of delimiters
|
||||
- `2` Around the 2nd occurrences of delimiters
|
||||
- ...
|
||||
- `*` Around all occurrences of delimiters
|
||||
- `**` Left-right alternating alignment around all delimiters
|
||||
- `-` Around the last occurrences of delimiters (`-1`)
|
||||
- `-2` Around the second to last occurrences of delimiters
|
||||
- ...
|
||||
4. Delimiter key (a single keystroke; <Space>, `=`, `:`, `.`, `|`, `&`, `#`, `,`)
|
||||
|
||||
|
||||
Predefined alignment rules~
|
||||
*easy-align-predefined-alignment-rules*
|
||||
*easy-align-5-3-1*
|
||||
|
||||
--------------+--------------------------------------------------------------------
|
||||
Delimiter key | Description/Use cases ~
|
||||
--------------+--------------------------------------------------------------------
|
||||
<Space> | General alignment around whitespaces
|
||||
`=` | Operators containing equals sign ( `=` , `==,` `!=` , `+=` , `&&=` , ...)
|
||||
`:` | Suitable for formatting JSON or YAML
|
||||
`.` | Multi-line method chaining
|
||||
`,` | Multi-line method arguments
|
||||
`&` | LaTeX tables (matches `&` and `\\` )
|
||||
`#` | Ruby/Python comments
|
||||
`"` | Vim comments
|
||||
<Bar> | Table markdown
|
||||
--------------+--------------------------------------------------------------------
|
||||
|
||||
*g:easy_align_delimiters*
|
||||
|
||||
You can override these default rules or define your own rules with
|
||||
`g:easy_align_delimiters`, which will be described in {the later section}{5}.
|
||||
|
||||
{5} https://github.com/junegunn/vim-easy-align#extending-alignment-rules
|
||||
|
||||
|
||||
Examples~
|
||||
*easy-align-examples*
|
||||
*easy-align-5-3-2*
|
||||
|
||||
------------------+------------------------------------+--------------------
|
||||
With visual map | Description | Equivalent command ~
|
||||
------------------+------------------------------------+--------------------
|
||||
<Enter><Space> | Around 1st whitespaces | :'<,'>EasyAlign\
|
||||
<Enter>2<Space> | Around 2nd whitespaces | :'<,'>EasyAlign2\
|
||||
<Enter>-<Space> | Around the last whitespaces | :'<,'>EasyAlign-\
|
||||
<Enter>-2<Space> | Around the 2nd to last whitespaces | :'<,'>EasyAlign-2\
|
||||
<Enter>: | Around 1st colon ( `key: value` ) | :'<,'>EasyAlign:
|
||||
<Enter><Right>: | Around 1st colon ( `key : value` ) | :'<,'>EasyAlign:<l1
|
||||
<Enter>= | Around 1st operators with = | :'<,'>EasyAlign=
|
||||
<Enter>3= | Around 3rd operators with = | :'<,'>EasyAlign3=
|
||||
<Enter>*= | Around all operators with = | :'<,'>EasyAlign*=
|
||||
<Enter>**= | Left-right alternating around = | :'<,'>EasyAlign**=
|
||||
<Enter><Enter>= | Right alignment around 1st = | :'<,'>EasyAlign!=
|
||||
<Enter><Enter>**= | Right-left alternating around = | :'<,'>EasyAlign!**=
|
||||
------------------+------------------------------------+--------------------
|
||||
|
||||
|
||||
Using regular expressions~
|
||||
*easy-align-using-regular-expressions*
|
||||
*easy-align-5-3-3*
|
||||
|
||||
Instead of finishing the command with a predefined delimiter key, you can type
|
||||
in a regular expression after CTRL-/ or CTRL-X key. For example, if you want
|
||||
to align text around all occurrences of numbers:
|
||||
|
||||
- <Enter>
|
||||
- `*`
|
||||
- CTRL-X
|
||||
- `[0-9]\+`
|
||||
|
||||
|
||||
Alignment options in interactive mode~
|
||||
*easy-align-alignment-options-in-interactive-mode*
|
||||
*easy-align-5-3-4*
|
||||
|
||||
While in interactive mode, you can set alignment options using special
|
||||
shortcut keys listed below. The meaning of each option will be described in
|
||||
{the following sections}{6}.
|
||||
|
||||
--------+--------------------+---------------------------------------------------
|
||||
Key | Option | Values ~
|
||||
--------+--------------------+---------------------------------------------------
|
||||
CTRL-F | `filter` | Input string ( `[gv]/.*/?` )
|
||||
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']
|
||||
CTRL-A | `align` | Input string ( `/[lrc]+\*{0,2}/` )
|
||||
<Left> | `stick_to_left` | `{ 'stick_to_left': 1, 'left_margin': 0 }`
|
||||
<Right> | `stick_to_left` | `{ 'stick_to_left': 0, 'left_margin': 1 }`
|
||||
<Down> | `*_margin` | `{ 'left_margin': 0, 'right_margin': 0 }`
|
||||
--------+--------------------+---------------------------------------------------
|
||||
|
||||
{6} https://github.com/junegunn/vim-easy-align#alignment-options
|
||||
|
||||
|
||||
< Live interactive mode >_____________________________________________________~
|
||||
*easy-align-live-interactive-mode*
|
||||
*easy-align-5-4*
|
||||
|
||||
If you're performing a complex alignment where multiple options should be
|
||||
carefully adjusted, try "live interactive mode" where you can preview the
|
||||
result of the alignment on-the-fly as you type in.
|
||||
|
||||
Live interactive mode can be started with either <Plug>(LiveEasyAlign) map or
|
||||
`:LiveEasyAlign` command. Or you can switch to live interactive mode while in
|
||||
ordinary interactive mode by pressing CTRL-P. (P for Preview)
|
||||
|
||||
In live interactive mode, you have to type in the same delimiter (or CTRL-X on
|
||||
regular expression) again to finalize the alignment. This allows you to
|
||||
preview the result of the alignment and freely change the delimiter using
|
||||
backspace key without leaving the interactive mode.
|
||||
|
||||
|
||||
< Non-interactive mode >______________________________________________________~
|
||||
*easy-align-non-interactive-mode*
|
||||
*easy-align-5-5*
|
||||
|
||||
Instead of starting interactive mode, you can use declarative, non-interactive
|
||||
`:EasyAlign` command.
|
||||
>
|
||||
" Using predefined alignment rules
|
||||
" :EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
|
||||
:EasyAlign :
|
||||
:EasyAlign =
|
||||
:EasyAlign *=
|
||||
:EasyAlign 3\
|
||||
|
||||
" Using arbitrary regular expressions
|
||||
" :EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
|
||||
:EasyAlign /[:;]\+/
|
||||
:EasyAlign 2/[:;]\+/
|
||||
:EasyAlign */[:;]\+/
|
||||
:EasyAlign **/[:;]\+/
|
||||
<
|
||||
A command can end with alignment options, {each of which will be discussed in
|
||||
detail later}{6}, in Vim dictionary format.
|
||||
|
||||
- `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': 0 }`
|
||||
|
||||
`stick_to_left` of 1 means that the matched delimiter should be positioned
|
||||
right next to the preceding token, and `left_margin` of 0 removes the margin
|
||||
on the left. So we get:
|
||||
>
|
||||
apple;: banana:: cake
|
||||
data;; exchange:; format
|
||||
<
|
||||
Option names are fuzzy-matched, so you can write as follows:
|
||||
|
||||
- `:EasyAlign * /[:;]\+/ { 'stl': 1, 'l': 0 }`
|
||||
|
||||
You can even omit spaces between the arguments, so concisely (or cryptically):
|
||||
|
||||
- `:EasyAlign*/[:;]\+/{'s':1,'l':0}`
|
||||
|
||||
Nice. But let's make it even shorter. Option values can be written in
|
||||
shorthand notation.
|
||||
|
||||
- `:EasyAlign*/[:;]\+/<l0`
|
||||
|
||||
The following table summarizes the shorthand notation.
|
||||
|
||||
-------------------+-----------
|
||||
Option | Expression~
|
||||
-------------------+-----------
|
||||
`filter` | `[gv]/.*/`
|
||||
`left_margin` | `l[0-9]+`
|
||||
`right_margin` | `r[0-9]+`
|
||||
`stick_to_left` | `<` or `>`
|
||||
`ignore_unmatched` | `iu[01]`
|
||||
`ignore_groups` | `ig\[.*\]`
|
||||
`align` | `a[lrc*]*`
|
||||
`delimiter_align` | `d[lrc]`
|
||||
`indentation` | `i[ksdn]`
|
||||
-------------------+-----------
|
||||
|
||||
For your information, the same operation can be done in interactive mode as
|
||||
follows:
|
||||
|
||||
- <Enter>
|
||||
- `*`
|
||||
- <Left>
|
||||
- CTRL-X
|
||||
- `[:;]\+`
|
||||
|
||||
{6} https://github.com/junegunn/vim-easy-align#alignment-options
|
||||
|
||||
|
||||
< Partial alignment in blockwise-visual mode >________________________________~
|
||||
*easy-align-partial-alignment-in-blockwise-visual-mode*
|
||||
*easy-align-5-6*
|
||||
|
||||
In blockwise-visual mode (CTRL-V), EasyAlign command aligns only the selected
|
||||
text in the block, instead of the whole lines in the range.
|
||||
|
||||
Consider the following case where you want to align text around `=>`
|
||||
operators.
|
||||
>
|
||||
my_hash = { :a => 1,
|
||||
:aa => 2,
|
||||
:aaa => 3 }
|
||||
<
|
||||
In non-blockwise visual mode (`v` / `V`), <Enter>= won't work since the
|
||||
assignment operator in the first line gets in the way. So we instead enter
|
||||
blockwise-visual mode (CTRL-V), and select the text around`=>` operators, then
|
||||
press <Enter>=.
|
||||
>
|
||||
my_hash = { :a => 1,
|
||||
:aa => 2,
|
||||
:aaa => 3 }
|
||||
<
|
||||
However, in this case, we don't really need blockwise visual mode since the
|
||||
same can be easily done using the negative N-th parameter: <Enter>-=
|
||||
|
||||
|
||||
*easy-align-6*
|
||||
ALIGNMENT OPTIONS *easy-align-alignment-options*
|
||||
==============================================================================
|
||||
|
||||
|
||||
< List of options >___________________________________________________________~
|
||||
*easy-align-list-of-options*
|
||||
*easy-align-6-1*
|
||||
|
||||
-------------------+---------+-----------------------+--------------------------------------------------------
|
||||
Option | Type | Default | Description ~
|
||||
-------------------+---------+-----------------------+--------------------------------------------------------
|
||||
`filter` | string | | Line filtering expression: `g/../` or `v/../`
|
||||
`left_margin` | number | 1 | Number of spaces to attach before delimiter
|
||||
`left_margin` | string | `' '` | String to attach before delimiter
|
||||
`right_margin` | number | 1 | Number of spaces to attach after delimiter
|
||||
`right_margin` | string | `' '` | String to attach after delimiter
|
||||
`stick_to_left` | boolean | 0 | Whether to position delimiter on the left-side
|
||||
`ignore_groups` | list | ["String', "Comment'] | Delimiters in these syntax highlight groups are ignored
|
||||
`ignore_unmatched` | boolean | 1 | Whether to ignore lines without matching delimiter
|
||||
`indentation` | string | `k` | Indentation method (keep, deep, shallow, none)
|
||||
`delimiter_align` | string | `r` | Determines how to align delimiters of different lengths
|
||||
`align` | string | `l` | Alignment modes for multiple occurrences of delimiters
|
||||
-------------------+---------+-----------------------+--------------------------------------------------------
|
||||
|
||||
There are 4 ways to set alignment options (from lowest precedence to highest):
|
||||
|
||||
1. Some option values can be set with corresponding global variables
|
||||
2. Option values can be specified in the definition of each alignment rule
|
||||
3. Option values can be given as arguments to `:EasyAlign` command
|
||||
4. Option values can be set in interactive mode using special shortcut keys
|
||||
|
||||
*g:easy_align_ignore_groups* *g:easy_align_ignore_unmatched*
|
||||
*g:easy_align_indentation* *g:easy_align_delimiter_align*
|
||||
|
||||
-------------------+-----------------+-------------+--------------------------------
|
||||
Option name | Shortcut key | Abbreviated | Global variable ~
|
||||
-------------------+-----------------+-------------+--------------------------------
|
||||
`filter` | CTRL-F | `[gv]/.*/` |
|
||||
`left_margin` | CTRL-L | `l[0-9]+` |
|
||||
`right_margin` | CTRL-R | `r[0-9]+` |
|
||||
`stick_to_left` | <Left>, <Right> | `<` or `>` |
|
||||
`ignore_groups` | CTRL-G | `ig\[.*\]` | `g:easy_align_ignore_groups`
|
||||
`ignore_unmatched` | CTRL-U | `iu[01]` | `g:easy_align_ignore_unmatched`
|
||||
`indentation` | CTRL-I | `i[ksdn]` | `g:easy_align_indentation`
|
||||
`delimiter_align` | CTRL-D | `d[lrc]` | `g:easy_align_delimiter_align`
|
||||
`align` | CTRL-A | `a[lrc*]*` |
|
||||
-------------------+-----------------+-------------+--------------------------------
|
||||
|
||||
|
||||
< Filtering lines >___________________________________________________________~
|
||||
*easy-align-filtering-lines*
|
||||
*easy-align-6-2*
|
||||
|
||||
With `filter` option, you can align lines that only match or do not match a
|
||||
given pattern. There are several ways to set the pattern.
|
||||
|
||||
1. Press CTRL-F in interactive mode and type in `g/pat/` or `v/pat/`
|
||||
2. In command-line, it can be written in dictionary format: `{'filter':
|
||||
'g/pat/'}`
|
||||
3. Or in shorthand notation: `g/pat/` or `v/pat/`
|
||||
|
||||
(You don't need to escape "/'s in the regular expression)
|
||||
|
||||
|
||||
Examples~
|
||||
|
||||
*easy-align-6-2-1*
|
||||
>
|
||||
" Start interactive mode with filter option set to g/hello/
|
||||
EasyAlign g/hello/
|
||||
|
||||
" Start live interactive mode with filter option set to v/goodbye/
|
||||
LiveEasyAlign v/goodbye/
|
||||
|
||||
" Align the lines with 'hi' around the first colons
|
||||
EasyAlign:g/hi/
|
||||
<
|
||||
|
||||
< Ignoring delimiters in comments or strings >________________________________~
|
||||
*easy-align-ignoring-delimiters-in-comments-or-strings*
|
||||
*easy-align-6-3*
|
||||
|
||||
EasyAlign can be configured to ignore delimiters in certain syntax highlight
|
||||
groups, such as code comments or strings. By default, delimiters 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']
|
||||
|
||||
" any of the following regular expressions, it will be ignored.
|
||||
let g:easy_align_ignore_groups = ['Comment', 'String']
|
||||
<
|
||||
For example, the following paragraph
|
||||
|
||||
>
|
||||
{
|
||||
# Quantity of apples: 1
|
||||
apple: 1,
|
||||
@@ -89,9 +530,9 @@ For example, the following paragraph
|
||||
# Quantity of grape:fruits: 3
|
||||
'grape:fruits': 3
|
||||
}
|
||||
|
||||
becomes as follows on `<Enter>:`
|
||||
|
||||
<
|
||||
becomes as follows on <Enter>: (or `:EasyAlign:`)
|
||||
>
|
||||
{
|
||||
# Quantity of apples: 1
|
||||
apple: 1,
|
||||
@@ -100,16 +541,18 @@ becomes as follows on `<Enter>:`
|
||||
# Quantity of grape:fruits: 3
|
||||
'grape:fruits': 3
|
||||
}
|
||||
|
||||
<
|
||||
Naturally, this feature only works when syntax highlighting is enabled.
|
||||
|
||||
You can change the default rule by defining `g:easy_align_ignores` array.
|
||||
You can change the default rule by using one of these 4 methods.
|
||||
|
||||
" Ignore nothing!
|
||||
let g:easy_align_ignores = []
|
||||
|
||||
Then you get,
|
||||
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:ig[]`
|
||||
|
||||
For example if you set `ignore_groups` option to be an empty list, you get
|
||||
>
|
||||
{
|
||||
# Quantity of apples: 1
|
||||
apple: 1,
|
||||
@@ -118,16 +561,41 @@ Then you get,
|
||||
# Quantity of grape: fruits: 3
|
||||
'grape: fruits': 3
|
||||
}
|
||||
<
|
||||
If a pattern in `ignore_groups` is prepended by a `!`, it will have the
|
||||
opposite meaning. For instance, if `ignore_groups` is given as `['!Comment']`,
|
||||
delimiters that are not highlighted as Comment will be ignored during the
|
||||
alignment.
|
||||
|
||||
To make `ignore_groups` work, and to debug the related issues, it is useful to
|
||||
know which highlight group a certain location in a file belongs to. A special
|
||||
function exists for this purpose, returning exactly the name of the highlight
|
||||
group that is used by the easy align plugin.
|
||||
>
|
||||
" Highlight group name of the cursor position
|
||||
echo easy_align#get_highlight_group_name()
|
||||
|
||||
Handling unmatched lines *g:easy_align_ignore_unmatched*
|
||||
-------------------------------------------------------------------------
|
||||
" Highlight group name of the line 10, column 20
|
||||
echo easy_align#get_highlight_group_name(10, 20)
|
||||
<
|
||||
|
||||
Lines without any matching delimiter are ignored as well (except in
|
||||
right-justification mode).
|
||||
< Ignoring unmatched lines >__________________________________________________~
|
||||
*easy-align-ignoring-unmatched-lines*
|
||||
*easy-align-6-4*
|
||||
|
||||
For example, when aligning the following code block around the colons,
|
||||
`ignore_unmatched` option determines how EasyAlign command processes lines
|
||||
that do not have N-th delimiter.
|
||||
|
||||
1. In left-alignment mode, they are ignored
|
||||
2. In right or center-alignment mode, they are not ignored, and the last tokens
|
||||
from those lines are aligned as well as if there is an invisible trailing
|
||||
delimiter at the end of each line
|
||||
3. If `ignore_unmatched` is 1, they are ignored regardless of the alignment mode
|
||||
4. If `ignore_unmatched` is 0, they are not ignored regardless of the mode
|
||||
|
||||
Let's take an example. When we align the following code block around the (1st)
|
||||
colons,
|
||||
>
|
||||
{
|
||||
apple: proc {
|
||||
this_line_does_not_have_a_colon
|
||||
@@ -135,9 +603,9 @@ For example, when aligning the following code block around the colons,
|
||||
bananas: 2,
|
||||
grapefruits: 3
|
||||
}
|
||||
|
||||
<
|
||||
this is usually what we want.
|
||||
|
||||
>
|
||||
{
|
||||
apple: proc {
|
||||
this_line_does_not_have_a_colon
|
||||
@@ -145,13 +613,18 @@ this is usually what we want.
|
||||
bananas: 2,
|
||||
grapefruits: 3
|
||||
}
|
||||
<
|
||||
However, we can override this default behavior by setting `ignore_unmatched`
|
||||
option to zero using one of the following methods.
|
||||
|
||||
However, this default behavior is also configurable.
|
||||
|
||||
let g:easy_align_ignore_unmatched = 0
|
||||
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:iu0`
|
||||
|
||||
Then we get,
|
||||
|
||||
>
|
||||
{
|
||||
apple: proc {
|
||||
this_line_does_not_have_a_colon
|
||||
@@ -159,27 +632,271 @@ Then we get,
|
||||
bananas: 2,
|
||||
grapefruits: 3
|
||||
}
|
||||
<
|
||||
|
||||
< Aligning delimiters of different lengths >__________________________________~
|
||||
*easy-align-aligning-delimiters-of-different-lengths*
|
||||
*easy-align-6-5*
|
||||
|
||||
Global `g:easy_align_delimiter_align` option and rule-wise/command-wise
|
||||
`delimiter_align` option determines how matched delimiters of different
|
||||
lengths are aligned.
|
||||
>
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
<
|
||||
By default, delimiters are right-aligned as follows.
|
||||
>
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
<
|
||||
However, with `:EasyAlign=dl`, delimiters are left-aligned.
|
||||
>
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
<
|
||||
And on `:EasyAlign=dc`, center-aligned.
|
||||
>
|
||||
apple = 1
|
||||
banana += apple
|
||||
cake ||= banana
|
||||
<
|
||||
In interactive mode, you can change the option value with CTRL-D key.
|
||||
|
||||
|
||||
Extending alignment rules *g:easy_align_delimiters*
|
||||
-------------------------------------------------------------------------
|
||||
< Adjusting indentation >_____________________________________________________~
|
||||
*easy-align-adjusting-indentation*
|
||||
*easy-align-6-6*
|
||||
|
||||
By default :EasyAlign command keeps the original indentation of the lines. But
|
||||
then again we have `indentation` option. See the following example.
|
||||
>
|
||||
# Lines with different indentation
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Default: _k_eep the original indentation
|
||||
# :EasyAlign=
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Use the _s_hallowest indentation among the lines
|
||||
# :EasyAlign=is
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Use the _d_eepest indentation among the lines
|
||||
# :EasyAlign=id
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
|
||||
# Indentation: _n_one
|
||||
# :EasyAlign=in
|
||||
apple = 1
|
||||
banana = 2
|
||||
cake = 3
|
||||
daisy = 4
|
||||
eggplant = 5
|
||||
<
|
||||
In interactive mode, you can change the option value with CTRL-I key.
|
||||
|
||||
|
||||
< Alignments over multiple occurrences of delimiters >________________________~
|
||||
*easy-align-alignments-over-multiple-occurrences-of-delimiters*
|
||||
*easy-align-6-7*
|
||||
|
||||
As stated above, "N-th" parameter is used to target specific occurrences of
|
||||
the delimiter when it appears multiple times in each line.
|
||||
|
||||
To recap:
|
||||
>
|
||||
" Left-alignment around the FIRST occurrences of delimiters
|
||||
:EasyAlign =
|
||||
|
||||
" Left-alignment around the SECOND occurrences of delimiters
|
||||
:EasyAlign 2=
|
||||
|
||||
" Left-alignment around the LAST occurrences of delimiters
|
||||
:EasyAlign -=
|
||||
|
||||
" Left-alignment around ALL occurrences of delimiters
|
||||
:EasyAlign *=
|
||||
|
||||
" Left-right ALTERNATING alignment around all occurrences of delimiters
|
||||
:EasyAlign **=
|
||||
|
||||
" Right-left ALTERNATING alignment around all occurrences of delimiters
|
||||
:EasyAlign! **=
|
||||
<
|
||||
In addition to these, you can fine-tune alignments over multiple occurrences
|
||||
of the delimiters with "align' option. (The option can also be set in
|
||||
interactive mode with the special key CTRL-A)
|
||||
>
|
||||
" Left alignment over the first two occurrences of delimiters
|
||||
:EasyAlign = { 'align': 'll' }
|
||||
|
||||
" Right, left, center alignment over the 1st to 3rd occurrences of delimiters
|
||||
:EasyAlign = { 'a': 'rlc' }
|
||||
|
||||
" Using shorthand notation
|
||||
:EasyAlign = arlc
|
||||
|
||||
" Right, left, center alignment over the 2nd to 4th occurrences of delimiters
|
||||
:EasyAlign 2=arlc
|
||||
|
||||
" (*) Repeating alignments (default: l, r, or c)
|
||||
" Right, left, center, center, center, center, ...
|
||||
:EasyAlign *=arlc
|
||||
|
||||
" (**) Alternating alignments (default: lr or rl)
|
||||
" Right, left, center, right, left, center, ...
|
||||
:EasyAlign **=arlc
|
||||
|
||||
" Right, left, center, center, center, ... repeating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3=arlc*
|
||||
|
||||
" Right, left, center, right, left, center, ... alternating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3=arlc**
|
||||
<
|
||||
|
||||
< Extending alignment rules >_________________________________________________~
|
||||
*easy-align-extending-alignment-rules*
|
||||
*easy-align-6-8*
|
||||
|
||||
Although the default rules should cover the most of the use cases, you can
|
||||
extend the rules by setting a dictionary named `g:easy_align_delimiters`.
|
||||
|
||||
You may refer to the definitions of the default alignment rules {here}{7}.
|
||||
|
||||
{7} https://github.com/junegunn/vim-easy-align/blob/2.9.6/autoload/easy_align.vim#L32-L46
|
||||
|
||||
|
||||
Examples~
|
||||
|
||||
*easy-align-6-8-1*
|
||||
>
|
||||
let g:easy_align_delimiters = {
|
||||
\ '>': { 'pattern': '>>\|=>\|>' },
|
||||
\ '/': { 'pattern': '//\+' },
|
||||
\ '#': { 'pattern': '#\+' },
|
||||
\ '/': {
|
||||
\ 'pattern': '//\+\|/\*\|\*/',
|
||||
\ 'delimiter_align': 'l',
|
||||
\ 'ignore_groups': ['!Comment'] },
|
||||
\ ']': {
|
||||
\ 'pattern': '[\[\]]',
|
||||
\ 'margin_left': '',
|
||||
\ 'margin_right': '',
|
||||
\ 'pattern': '[[\]]',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0,
|
||||
\ 'stick_to_left': 0
|
||||
\ },
|
||||
\ ')': {
|
||||
\ 'pattern': '[()]',
|
||||
\ 'margin_left': '',
|
||||
\ 'margin_right': '',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0,
|
||||
\ 'stick_to_left': 0
|
||||
\ },
|
||||
\ 'd': {
|
||||
\ 'pattern': ' \(\S\+\s*[;=]\)\@=',
|
||||
\ 'left_margin': 0,
|
||||
\ 'right_margin': 0
|
||||
\ }
|
||||
\ }
|
||||
<
|
||||
|
||||
*easy-align-7*
|
||||
OTHER OPTIONS *easy-align-other-options*
|
||||
==============================================================================
|
||||
|
||||
|
||||
< Disabling &foldmethod during alignment >____________________________________~
|
||||
*easy-align-disabling-foldmethod-during-alignment*
|
||||
*easy-align-7-1*
|
||||
|
||||
*g:easy_align_bypass_fold*
|
||||
|
||||
{It is reported}{8} that 'foldmethod' value of `expr` or `syntax` can
|
||||
significantly slow down the alignment when editing a large, complex file with
|
||||
many folds. To alleviate this issue, EasyAlign provides an option to
|
||||
temporarily set 'foldmethod' to `manual` during the alignment task. In order
|
||||
to enable this feature, set `g:easy_align_bypass_fold` switch to 1.
|
||||
>
|
||||
let g:easy_align_bypass_fold = 1
|
||||
<
|
||||
{8} https://github.com/junegunn/vim-easy-align/issues/14
|
||||
|
||||
|
||||
< Left/right/center mode switch in interactive mode >_________________________~
|
||||
*easy-align-left-right-center-mode-switch-in-interactive-mode*
|
||||
*easy-align-7-2*
|
||||
|
||||
In interactive mode, you can choose the alignment mode you want by pressing
|
||||
enter keys. The non-bang command, `:EasyAlign` starts in left-alignment mode
|
||||
and changes to right and center mode as you press enter keys, while the bang
|
||||
version first starts in right-alignment mode.
|
||||
|
||||
- `:EasyAlign`
|
||||
- Left, Right, Center
|
||||
- `:EasyAlign!`
|
||||
- Right, Left, Center
|
||||
|
||||
If you do not prefer this default mode transition, you can define your own
|
||||
settings as follows.
|
||||
|
||||
*g:easy_align_interactive_modes* *g:easy_align_bang_interactive_modes*
|
||||
>
|
||||
let g:easy_align_interactive_modes = ['l', 'r']
|
||||
let g:easy_align_bang_interactive_modes = ['c', 'r']
|
||||
<
|
||||
|
||||
*easy-align-8*
|
||||
ADVANCED EXAMPLES AND USE CASES *easy-align-advanced-examples-and-use-cases*
|
||||
==============================================================================
|
||||
|
||||
See {EXAMPLES.md}{9} for more examples.
|
||||
|
||||
{9} https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md
|
||||
|
||||
|
||||
*easy-align-9*
|
||||
RELATED WORK *easy-align-related-work*
|
||||
==============================================================================
|
||||
|
||||
- {DrChip's Alignment Tool for Vim}{10}
|
||||
- {Tabular}{11}
|
||||
|
||||
{10} http://www.drchip.org/astronaut/vim/align.html
|
||||
{11} https://github.com/godlygeek/tabular
|
||||
|
||||
|
||||
*easy-align-10*
|
||||
AUTHOR *easy-align-author*
|
||||
==============================================================================
|
||||
|
||||
{Junegunn Choi}{12}
|
||||
|
||||
{12} https://github.com/junegunn
|
||||
|
||||
|
||||
*easy-align-11*
|
||||
LICENSE *easy-align-license*
|
||||
==============================================================================
|
||||
|
||||
MIT
|
||||
|
||||
==============================================================================
|
||||
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
" Copyright (c) 2013 Junegunn Choi
|
||||
" Copyright (c) 2014 Junegunn Choi
|
||||
"
|
||||
" MIT License
|
||||
"
|
||||
@@ -26,5 +26,118 @@ if exists("g:loaded_easy_align_plugin")
|
||||
endif
|
||||
let g:loaded_easy_align_plugin = 1
|
||||
|
||||
command! -nargs=* -range EasyAlign <line1>,<line2>call easy_align#align(0, <f-args>)
|
||||
command! -nargs=* -range EasyAlignRight <line1>,<line2>call easy_align#align(1, <f-args>)
|
||||
command! -nargs=* -range -bang EasyAlign <line1>,<line2>call easy_align#align(<bang>0, 0, 'command', <q-args>)
|
||||
command! -nargs=* -range -bang LiveEasyAlign <line1>,<line2>call easy_align#align(<bang>0, 1, 'command', <q-args>)
|
||||
|
||||
let s:last_command = 'EasyAlign'
|
||||
|
||||
function! s:abs(v)
|
||||
return a:v >= 0 ? a:v : - a:v
|
||||
endfunction
|
||||
|
||||
function! s:remember_visual(mode)
|
||||
let s:last_visual = [a:mode, s:abs(line("'>") - line("'<")), s:abs(col("'>") - col("'<"))]
|
||||
endfunction
|
||||
|
||||
function! s:repeat_visual()
|
||||
let [mode, ldiff, cdiff] = s:last_visual
|
||||
let cmd = 'normal! '.mode
|
||||
if ldiff > 0
|
||||
let cmd .= ldiff . 'j'
|
||||
endif
|
||||
|
||||
let ve_save = &virtualedit
|
||||
try
|
||||
if mode == "\<C-V>"
|
||||
if cdiff > 0
|
||||
let cmd .= cdiff . 'l'
|
||||
endif
|
||||
set virtualedit+=block
|
||||
endif
|
||||
execute cmd.":\<C-r>=g:easy_align_last_command\<Enter>\<Enter>"
|
||||
call s:set_repeat()
|
||||
finally
|
||||
if ve_save != &virtualedit
|
||||
let &virtualedit = ve_save
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:repeat_in_visual()
|
||||
if exists('g:easy_align_last_command')
|
||||
call s:remember_visual(visualmode())
|
||||
call s:repeat_visual()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:set_repeat()
|
||||
silent! call repeat#set("\<Plug>(EasyAlignRepeat)")
|
||||
endfunction
|
||||
|
||||
function! s:generic_easy_align_op(type, vmode, live)
|
||||
if !&modifiable
|
||||
if a:vmode
|
||||
normal! gv
|
||||
endif
|
||||
return
|
||||
endif
|
||||
let sel_save = &selection
|
||||
let &selection = "inclusive"
|
||||
|
||||
if a:vmode
|
||||
let vmode = a:type
|
||||
let [l1, l2] = ["'<", "'>"]
|
||||
call s:remember_visual(vmode)
|
||||
else
|
||||
let vmode = ''
|
||||
let [l1, l2] = [line("'["), line("']")]
|
||||
unlet! s:last_visual
|
||||
endif
|
||||
|
||||
try
|
||||
let range = l1.','.l2
|
||||
if get(g:, 'easy_align_need_repeat', 0)
|
||||
execute range . g:easy_align_last_command
|
||||
else
|
||||
execute range . "call easy_align#align(0, a:live, vmode, '')"
|
||||
end
|
||||
call s:set_repeat()
|
||||
finally
|
||||
let &selection = sel_save
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:easy_align_op(type, ...)
|
||||
call s:generic_easy_align_op(a:type, a:0, 0)
|
||||
endfunction
|
||||
|
||||
function! s:live_easy_align_op(type, ...)
|
||||
call s:generic_easy_align_op(a:type, a:0, 1)
|
||||
endfunction
|
||||
|
||||
function! s:easy_align_repeat()
|
||||
if exists('s:last_visual')
|
||||
call s:repeat_visual()
|
||||
else
|
||||
try
|
||||
let g:easy_align_need_repeat = 1
|
||||
normal! .
|
||||
finally
|
||||
unlet! g:easy_align_need_repeat
|
||||
endtry
|
||||
endif
|
||||
endfunction
|
||||
|
||||
nnoremap <silent> <Plug>(EasyAlign) :set opfunc=<SID>easy_align_op<Enter>g@
|
||||
vnoremap <silent> <Plug>(EasyAlign) :<C-U>call <SID>easy_align_op(visualmode(), 1)<Enter>
|
||||
nnoremap <silent> <Plug>(LiveEasyAlign) :set opfunc=<SID>live_easy_align_op<Enter>g@
|
||||
vnoremap <silent> <Plug>(LiveEasyAlign) :<C-U>call <SID>live_easy_align_op(visualmode(), 1)<Enter>
|
||||
|
||||
" vim-repeat support
|
||||
nnoremap <silent> <Plug>(EasyAlignRepeat) :call <SID>easy_align_repeat()<Enter>
|
||||
vnoremap <silent> <Plug>(EasyAlignRepeat) :<C-U>call <SID>repeat_in_visual()<Enter>
|
||||
|
||||
" Backward-compatibility (deprecated)
|
||||
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@
|
||||
|
||||
" vim: set et sw=2 :
|
||||
|
||||
13
test/README.md
Normal file
13
test/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
Test cases for vim-easy-align
|
||||
=============================
|
||||
|
||||
### Prerequisite
|
||||
|
||||
- [Vader.vim](https://github.com/junegunn/vader.vim)
|
||||
|
||||
### Run
|
||||
|
||||
```
|
||||
./run
|
||||
```
|
||||
|
||||
22
test/blockwise.vader
Normal file
22
test/blockwise.vader
Normal file
@@ -0,0 +1,22 @@
|
||||
Include: include/setup.vader
|
||||
|
||||
Given clojure:
|
||||
(def world [[1 1 1 1 1]
|
||||
[999 999 999 999 1]
|
||||
[1 1 1 1 1]
|
||||
[1 999 999 999 999]
|
||||
[1 1 1 1 1]])
|
||||
|
||||
Do (Recursive alignment in blockwise-visual mode):
|
||||
f[;
|
||||
\<C-V>G
|
||||
\<Enter>*\<Space>
|
||||
|
||||
Expect clojure:
|
||||
(def world [[1 1 1 1 1]
|
||||
[999 999 999 999 1]
|
||||
[1 1 1 1 1]
|
||||
[1 999 999 999 999]
|
||||
[1 1 1 1 1]])
|
||||
|
||||
Include: include/teardown.vader
|
||||
191
test/commandline.vader
Normal file
191
test/commandline.vader
Normal file
@@ -0,0 +1,191 @@
|
||||
Include: include/setup.vader
|
||||
|
||||
Given (fruits):
|
||||
apple;:;;banana::cake
|
||||
data;;exchange:;::format
|
||||
|
||||
Execute (regular expression):
|
||||
%EasyAlign/[:;]\+/
|
||||
AssertEqual ':EasyAlign /[:;]\+/', g:easy_align_last_command
|
||||
|
||||
Expect:
|
||||
apple ;:;; banana::cake
|
||||
data ;; exchange:;::format
|
||||
|
||||
Execute (options dictionary):
|
||||
%EasyAlign/[:;]\+/{ 'left_margin': '<', 'right_margin': 3 }
|
||||
|
||||
Expect:
|
||||
apple<;:;; banana::cake
|
||||
data < ;; exchange:;::format
|
||||
|
||||
Execute (fuzzy matching):
|
||||
%EasyAlign/[:;]\+/{ 'l':'<', 'r': '>'}
|
||||
|
||||
Expect:
|
||||
apple<;:;;>banana::cake
|
||||
data < ;;>exchange:;::format
|
||||
|
||||
Execute (shorthand notation of margin):
|
||||
%EasyAlign/[:;]\+/l0r0
|
||||
|
||||
Expect:
|
||||
apple;:;;banana::cake
|
||||
data ;;exchange:;::format
|
||||
|
||||
Execute (delimiter align):
|
||||
%EasyAlign*/[:;]\+/l0r0dc
|
||||
|
||||
Expect:
|
||||
apple;:;;banana :: cake
|
||||
data ;; exchange:;::format
|
||||
|
||||
Execute (DEPRECATED: shorthand notation of mode_sequence and margin):
|
||||
%EasyAlign/[:;]\+/mrc*l2r2
|
||||
|
||||
Expect:
|
||||
apple ;:;; banana :: cake
|
||||
data ;; exchange :;:: format
|
||||
|
||||
Execute (shorthand notation of align and margin):
|
||||
%EasyAlign/[:;]\+/arc*l2r2
|
||||
|
||||
Expect:
|
||||
apple ;:;; banana :: cake
|
||||
data ;; exchange :;:: format
|
||||
|
||||
Execute (DEPRECATED: deep indentation):
|
||||
%EasyAlign/[:;]\+/mrc*l2r2
|
||||
%EasyAlign*/[:;]\+/idmrl*
|
||||
|
||||
Expect:
|
||||
apple ;:;; banana :: cake
|
||||
data ;; exchange :;:: format
|
||||
|
||||
Execute (deep indentation):
|
||||
%EasyAlign/[:;]\+/arc*l2r2
|
||||
%EasyAlign*/[:;]\+/idarl*
|
||||
|
||||
Expect:
|
||||
apple ;:;; banana :: cake
|
||||
data ;; exchange :;:: format
|
||||
|
||||
Execute (stick_to_left):
|
||||
%EasyAlign*/[:;]\+/stl1l0dlrm3
|
||||
|
||||
Expect:
|
||||
apple;:;; banana:: cake
|
||||
data;; exchange:;:: format
|
||||
|
||||
Execute (<):
|
||||
%EasyAlign*/[:;]\+/<l0dlrm3
|
||||
|
||||
Expect:
|
||||
apple;:;; banana:: cake
|
||||
data;; exchange:;:: format
|
||||
|
||||
Execute (>):
|
||||
%EasyAlign*/[:;]\+/l0dl<>rm3
|
||||
|
||||
Expect:
|
||||
apple;:;; banana :: cake
|
||||
data ;; exchange:;:: format
|
||||
|
||||
Execute (different regular expression):
|
||||
%EasyAlign*/../{'lm':'<','rm':'>'}
|
||||
|
||||
Expect:
|
||||
ap><pl><e;><:;><;b><an><an><a:><:c><ak>e
|
||||
da><ta><;;><ex><ch><an><ge><:;><::><fo><rm><at
|
||||
|
||||
Execute (merge different option notations):
|
||||
%EasyAlign*/../iu0 { 'l': '<', 'r': '>' }
|
||||
|
||||
Expect:
|
||||
ap><pl><e;><:;><;b><an><an><a:><:c><ak>e
|
||||
da><ta><;;><ex><ch><an><ge><:;><::><fo> <rm><at
|
||||
|
||||
Execute (Use current search pattern as delimiter if empty regular expression is given):
|
||||
/an
|
||||
%EasyAlign*//
|
||||
|
||||
Expect:
|
||||
apple;:;;b an an a::cake
|
||||
data;;exch an ge:;::format
|
||||
|
||||
Given javascript (json):
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */
|
||||
url: 'jdbc:mysql://localhost/test',
|
||||
database: "test",
|
||||
"user:pass":"r00t:pa55"
|
||||
};
|
||||
|
||||
Execute (default syntax-aware alignment):
|
||||
%EasyAlign*:
|
||||
|
||||
Expect javascript:
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */
|
||||
url: 'jdbc:mysql://localhost/test',
|
||||
database: "test",
|
||||
"user:pass": "r00t:pa55"
|
||||
};
|
||||
|
||||
Execute (do not ignore unmatched):
|
||||
%EasyAlign*:iu0
|
||||
|
||||
Expect javascript:
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */
|
||||
url: 'jdbc:mysql://localhost/test',
|
||||
database: "test",
|
||||
"user:pass": "r00t:pa55"
|
||||
};
|
||||
|
||||
Execute (do not ignore any group):
|
||||
%EasyAlign*:ig[]iu0
|
||||
|
||||
Expect javascript:
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc: mysql: //HOSTNAME/DATABASE) */
|
||||
url: 'jdbc: mysql: //localhost/test',
|
||||
database: "test",
|
||||
"user: pass": "r00t: pa55"
|
||||
};
|
||||
|
||||
Execute (ignore only strings):
|
||||
%EasyAlign*:ig['String']
|
||||
|
||||
Expect javascript:
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc: mysql: //HOSTNAME/DATABASE) */
|
||||
url: 'jdbc:mysql://localhost/test',
|
||||
database: "test",
|
||||
"user:pass": "r00t:pa55"
|
||||
};
|
||||
|
||||
Execute (ignore only comments):
|
||||
%EasyAlign*:ig['Comment']
|
||||
|
||||
Expect javascript:
|
||||
var jdbc = {
|
||||
// JDBC driver for MySQL database:
|
||||
driver: "com.mysql.jdbc.Driver",
|
||||
/* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */
|
||||
url: 'jdbc: mysql: //localhost/test',
|
||||
database: "test",
|
||||
"user: pass": "r00t: pa55"
|
||||
};
|
||||
|
||||
Include: include/teardown.vader
|
||||
13
test/extra.vader
Normal file
13
test/extra.vader
Normal file
@@ -0,0 +1,13 @@
|
||||
Include: include/setup.vader
|
||||
|
||||
Before:
|
||||
set nomodifiable
|
||||
After:
|
||||
set modifiable
|
||||
AssertEqual "hello\nworld\n", @"
|
||||
Given:
|
||||
hello
|
||||
world
|
||||
Do (#43 Do nothing when nomodifiable):
|
||||
vip\<enter>\<enter>\<enter>y
|
||||
|
||||
263
test/fixed.vader
Normal file
263
test/fixed.vader
Normal file
@@ -0,0 +1,263 @@
|
||||
Include: include/setup.vader
|
||||
|
||||
Given (Table):
|
||||
|a|b|c|d|
|
||||
| -|-|>-|-|
|
||||
|aaa|bbb|ccc|ddd|
|
||||
|
||||
Do (Partial alignment around 1st |):
|
||||
\<C-V>ljj\<Enter>|
|
||||
|
||||
Expect (Right margin should be correctly attached):
|
||||
| a|b|c|d|
|
||||
| -|-|>-|-|
|
||||
| aaa|bbb|ccc|ddd|
|
||||
|
||||
Given (empty buffer):
|
||||
|
||||
Execute (Aligning lines with many delimiters should not fail):
|
||||
call visualmode(1)
|
||||
call setline(1, repeat('|', &maxfuncdepth + 1))
|
||||
%EasyAlign*|
|
||||
AssertEqual (&maxfuncdepth + 1) * 3 - 2, len(getline(1))
|
||||
|
||||
Given:
|
||||
a | b | c
|
||||
aa | bb | cc
|
||||
|
||||
Execute:
|
||||
%EasyAlign*|iu0{'l':'<', 'r': '>'}
|
||||
|
||||
Expect:
|
||||
a <|>b <|>c
|
||||
aa<|>bb<|>cc
|
||||
|
||||
Given (Trailing delimiter):
|
||||
a | b | c |
|
||||
aa | bb | cc |
|
||||
|
||||
Execute:
|
||||
%EasyAlign*|iu0{'l':'<', 'r': '>'}
|
||||
|
||||
Expect:
|
||||
a <|>b <|>c <|
|
||||
aa<|>bb<|>cc<|
|
||||
|
||||
Given (Tab-indented code (#20)):
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=1
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=2
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=4
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=8
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=12
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
n2f = {}
|
||||
n2v = {}
|
||||
f2v = {}
|
||||
n2gv = {}
|
||||
n2vt = {}
|
||||
|
||||
Given (Tab-indented code (#20)):
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
# n2f= {}
|
||||
## n2v= {}
|
||||
# f2v = {}
|
||||
## n2gv = {}
|
||||
# n2vt = {}
|
||||
|
||||
Execute:
|
||||
set tabstop=12
|
||||
%EasyAlign=
|
||||
|
||||
Expect:
|
||||
class MyUnitTest(unittest.TestCase):
|
||||
def test_base(self):
|
||||
# n2f = {}
|
||||
## n2v = {}
|
||||
# f2v = {}
|
||||
## n2gv = {}
|
||||
# n2vt = {}
|
||||
|
||||
Given (Some text):
|
||||
a,b,c
|
||||
|
||||
d,e,f
|
||||
|
||||
Do (Select 1st line, align 3rd line):
|
||||
- First line
|
||||
V\<esc>
|
||||
- Last line
|
||||
G
|
||||
- Align
|
||||
\<space>Aip*,
|
||||
- Previous selection
|
||||
gv
|
||||
- Upcase
|
||||
U
|
||||
|
||||
Expect:
|
||||
A,B,C
|
||||
|
||||
d, e, f
|
||||
|
||||
Given c (#40 Ignored delimiters in LiveEasyAlign causes spurious undo):
|
||||
printf("foo = %f\n", foo);
|
||||
printf("foobar = %f\n", foobar);
|
||||
|
||||
Do:
|
||||
gUiw
|
||||
:%LiveEasyAlign\<enter>
|
||||
=\<bs>==
|
||||
|
||||
Expect c:
|
||||
PRINTF("foo = %f\n", foo);
|
||||
printf("foobar = %f\n", foobar);
|
||||
|
||||
* #50 Error when using delimiter alignment option
|
||||
Given:
|
||||
a|bbb|c
|
||||
aa|bb|cc
|
||||
|
||||
Do (#50 EasyAlign command with 'a' option):
|
||||
:%EasyAlign {'a': 'l'}\<cr>
|
||||
\<cr>
|
||||
*|
|
||||
|
||||
Expect (Some text):
|
||||
a | bbb | c
|
||||
aa | bb | cc
|
||||
|
||||
* #51 Repeat of visual <Plug>(LiveEasyAlign) broken
|
||||
Do (#51/#52 <Plug>(EasyAlignRepeat) in visual mode):
|
||||
V\<space>\<enter>\<enter>*||
|
||||
G
|
||||
V\<space>.
|
||||
|
||||
Expect:
|
||||
a | bbb | c
|
||||
aa | bb | cc
|
||||
|
||||
* #65 ?=
|
||||
Given:
|
||||
a?=b
|
||||
aa-=bb
|
||||
aaa?=bbb
|
||||
|
||||
Do (#65 Alignment around ?=):
|
||||
\<space>Aip=
|
||||
|
||||
Expect:
|
||||
a ?= b
|
||||
aa -= bb
|
||||
aaa ?= bbb
|
||||
|
||||
* #67 \v
|
||||
Given c:
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(SERV_PORT);
|
||||
|
||||
Execute (#67 \v breaks surrounding regex):
|
||||
%EasyAlign/\v(\=\s)@<=</
|
||||
|
||||
Expect:
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(SERV_PORT);
|
||||
|
||||
Execute (#67 \V followed by \v shouldn't matter):
|
||||
%EasyAlign/\v(\=\s)@<=<\V/
|
||||
|
||||
Expect:
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(SERV_PORT);
|
||||
|
||||
Execute (#67 \zs is now allowed):
|
||||
%EasyAlign/=\zs/
|
||||
|
||||
Expect:
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(SERV_PORT);
|
||||
|
||||
Include: include/teardown.vader
|
||||
|
||||
Given:
|
||||
hello = world bye all
|
||||
hello world = bye all
|
||||
hello world = foo all
|
||||
|
||||
Do (#105: Incorrectly detection of blockwise visual mode):
|
||||
\<c-v>jj\<esc>
|
||||
\<Space>Aip=
|
||||
|
||||
Expect:
|
||||
hello = world bye all
|
||||
hello world = bye all
|
||||
hello world = foo all
|
||||
24
test/fixme.vader
Normal file
24
test/fixme.vader
Normal file
@@ -0,0 +1,24 @@
|
||||
Include: include/setup.vader
|
||||
|
||||
# It is currently possible that EasyAlign command incorrectly judges
|
||||
# that it was executed in block-wise visual mode
|
||||
Given:
|
||||
a|b|c
|
||||
|
||||
Do (FIXME invalid judgement - block-wise visual mode):
|
||||
\<C-V>\<Esc>
|
||||
:%EasyAlign|\<CR>
|
||||
|
||||
Expect:
|
||||
a | b | c
|
||||
|
||||
Do (TODO Workaround: reset visualmode() on error):
|
||||
\<C-V>\<Esc>
|
||||
:%EasyAlign|\<CR>
|
||||
:%EasyAlign|\<CR>
|
||||
|
||||
Expect:
|
||||
a | b | c
|
||||
|
||||
Include: include/teardown.vader
|
||||
|
||||
38
test/include/setup.vader
Normal file
38
test/include/setup.vader
Normal file
@@ -0,0 +1,38 @@
|
||||
Execute (Clean up test environment):
|
||||
Save g:easy_align_ignore_groups, g:easy_align_ignore_unmatched
|
||||
Save g:easy_align_indentation, g:easy_align_delimiter_align
|
||||
Save g:easy_align_interactive_modes, g:easy_align_bang_interactive_modes
|
||||
Save g:easy_align_delimiters, g:easy_align_bypass_fold
|
||||
Save &tabstop, mapleader
|
||||
|
||||
unlet! g:easy_align_ignore_groups
|
||||
unlet! g:easy_align_ignore_unmatched
|
||||
unlet! g:easy_align_indentation
|
||||
unlet! g:easy_align_delimiter_align
|
||||
unlet! g:easy_align_interactive_modes
|
||||
unlet! g:easy_align_bang_interactive_modes
|
||||
unlet! g:easy_align_bypass_fold
|
||||
|
||||
let g:easy_align_delimiters = {}
|
||||
let mapleader = ' '
|
||||
vnoremap <silent> r<Enter> :EasyAlign!<Enter>
|
||||
vnoremap <silent> <Leader>r<Enter> :LiveEasyAlign!<Enter>
|
||||
|
||||
" " Legacy
|
||||
" vnoremap <silent> <Enter> :EasyAlign<Enter>
|
||||
" vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter>
|
||||
" nmap <leader>A <Plug>(EasyAlignOperator)
|
||||
|
||||
set ts=2
|
||||
|
||||
vmap <Enter> <Plug>(EasyAlign)
|
||||
vmap <leader><Enter> <Plug>(LiveEasyAlign)
|
||||
nmap <leader>A <Plug>(EasyAlign)
|
||||
vmap <leader>. <Plug>(EasyAlignRepeat)
|
||||
|
||||
silent! call plug#load('vim-easy-align')
|
||||
|
||||
Before:
|
||||
After:
|
||||
Given:
|
||||
|
||||
4
test/include/teardown.vader
Normal file
4
test/include/teardown.vader
Normal file
@@ -0,0 +1,4 @@
|
||||
Given:
|
||||
Execute (Restoring test environment):
|
||||
Restore
|
||||
|
||||
1886
test/interactive.vader
Normal file
1886
test/interactive.vader
Normal file
File diff suppressed because it is too large
Load Diff
11
test/run
Executable file
11
test/run
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd $(dirname $BASH_SOURCE)
|
||||
|
||||
vim -Nu <(cat << EOF
|
||||
syntax on
|
||||
for dep in ['vader.vim', 'vim-repeat']
|
||||
execute 'set rtp+=' . finddir(dep, expand('~/.vim').'/**')
|
||||
endfor
|
||||
set rtp+=..
|
||||
EOF) +Vader*
|
||||
158
test/tex.vader
Normal file
158
test/tex.vader
Normal file
@@ -0,0 +1,158 @@
|
||||
# http://en.wikibooks.org/wiki/LaTeX/Tables
|
||||
|
||||
Include: include/setup.vader
|
||||
|
||||
Given tex (table with escaped &):
|
||||
\begin{tabular}{ l c r }
|
||||
1&2&3\\
|
||||
44&55&66\\
|
||||
777&8\&8&999\\
|
||||
\end{tabular}
|
||||
|
||||
# FIXME vip doesn't work if folded
|
||||
Do (Align around all &s and \\s):
|
||||
VG\<Enter>*&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{ l c r }
|
||||
1 & 2 & 3 \\
|
||||
44 & 55 & 66 \\
|
||||
777 & 8\&8 & 999 \\
|
||||
\end{tabular}
|
||||
|
||||
Do (right-align with explicit ignore_unmatched):
|
||||
VG\<Enter>\<Enter>\<C-U>\<C-U>*&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{ l c r }
|
||||
1 & 2 & 3 \\
|
||||
44 & 55 & 66 \\
|
||||
777 & 8\&8 & 999 \\
|
||||
\end{tabular}
|
||||
|
||||
Do (center-align with explicit ignore_unmatched):
|
||||
VG\<Enter>\<Enter>\<Enter>\<C-U>\<C-U>*&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{ l c r }
|
||||
1 & 2 & 3 \\
|
||||
44 & 55 & 66 \\
|
||||
777 & 8\&8 & 999 \\
|
||||
\end{tabular}
|
||||
|
||||
Given tex (simple table with \hline):
|
||||
\begin{tabular}{ l c r }
|
||||
1&2&3\\ \hline
|
||||
44&55&66\\ \hline
|
||||
777&8\&&999\\ \hline
|
||||
\end{tabular}
|
||||
|
||||
Do:
|
||||
VG\<Enter>*&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{ l c r }
|
||||
1 & 2 & 3 \\ \hline
|
||||
44 & 55 & 66 \\ \hline
|
||||
777 & 8\& & 999 \\ \hline
|
||||
\end{tabular}
|
||||
|
||||
Given tex (table with lines w/o &s):
|
||||
\begin{tabular}{|r|l|}
|
||||
\hline
|
||||
7C0 & hexadecimal \\
|
||||
3700&octal \\ \cline{2-2}
|
||||
1111100000 & binary \\
|
||||
\hline \hline
|
||||
1984 & decimal \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
|
||||
Do (left-align*):
|
||||
VG\<Enter>*&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{|r|l|}
|
||||
\hline
|
||||
7C0 & hexadecimal \\
|
||||
3700 & octal \\ \cline{2-2}
|
||||
1111100000 & binary \\
|
||||
\hline \hline
|
||||
1984 & decimal \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
|
||||
Do(left-align* and right-align around 2nd):
|
||||
VG\<Enter>*&
|
||||
gv\<Enter>\<Enter>2&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{|r|l|}
|
||||
\hline
|
||||
7C0 & hexadecimal \\
|
||||
3700 & octal \\ \cline{2-2}
|
||||
1111100000 & binary \\
|
||||
\hline \hline
|
||||
1984 & decimal \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
|
||||
Given tex:
|
||||
\begin{tabular}{}
|
||||
32&1.14\e1&&5.65\e2&&&&1.16\e1&&1.28\e1&\\
|
||||
64&1.03\e1&0.1&4.98\e2&0.2&&&9.21\e2&0.3&1.02\e1&0.3\\
|
||||
128&9.86\e2&0.1&4.69\e2&0.1&&&8.46\e2&0.1&9.45\e2&0.1\\
|
||||
256&9.65\e2&0.0&4.59\e2&0.0&&&8.15\e2&0.1&9.11\e2&0.1\\
|
||||
% 512&9.55\e2&0.0&4.56\e2&0.0&&&8.01\e2&0.0&8.96\e2&0.0\\
|
||||
1024&9.49\e2&0.0&4.53\e2&0.0&&&7.94\e2&0.0&8.89\e2&0.0\\
|
||||
2048&9.47\e2&0.0&4.52\e2&0.0&&&7.91\e2&0.0&8.85\e2&0.0\\
|
||||
4096&9.46\e2&0.0&4.51\e2&0.0%&&&7.90\e2&0.0&8.83\e2&0.0\\
|
||||
8192&9.45\e2&0.0&4.51\e2&0.0&&&&&&\\
|
||||
\end{tabular}
|
||||
|
||||
Execute (Alignment around &s, foldmethod should not change):
|
||||
setlocal foldmethod=syntax
|
||||
%EasyAlign*&
|
||||
AssertEqual 'syntax', &l:foldmethod
|
||||
|
||||
setlocal foldmethod=manual
|
||||
%EasyAlign*&
|
||||
AssertEqual 'manual', &l:foldmethod
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{}
|
||||
32 & 1.14\e1 & & 5.65\e2 & & & & 1.16\e1 & & 1.28\e1 & \\
|
||||
64 & 1.03\e1 & 0.1 & 4.98\e2 & 0.2 & & & 9.21\e2 & 0.3 & 1.02\e1 & 0.3 \\
|
||||
128 & 9.86\e2 & 0.1 & 4.69\e2 & 0.1 & & & 8.46\e2 & 0.1 & 9.45\e2 & 0.1 \\
|
||||
256 & 9.65\e2 & 0.0 & 4.59\e2 & 0.0 & & & 8.15\e2 & 0.1 & 9.11\e2 & 0.1 \\
|
||||
% 512&9.55\e2&0.0&4.56\e2&0.0&&&8.01\e2&0.0&8.96\e2&0.0\\
|
||||
1024 & 9.49\e2 & 0.0 & 4.53\e2 & 0.0 & & & 7.94\e2 & 0.0 & 8.89\e2 & 0.0 \\
|
||||
2048 & 9.47\e2 & 0.0 & 4.52\e2 & 0.0 & & & 7.91\e2 & 0.0 & 8.85\e2 & 0.0 \\
|
||||
4096 & 9.46\e2 & 0.0 & 4.51\e2 & 0.0%&&&7.90\e2&0.0&8.83\e2&0.0\\
|
||||
8192 & 9.45\e2 & 0.0 & 4.51\e2 & 0.0 & & & & & & \\
|
||||
\end{tabular}
|
||||
|
||||
Execute (g:easy_align_bypass_fold set, foldmethod should not change):
|
||||
let g:easy_align_bypass_fold = 1
|
||||
setlocal foldmethod=syntax
|
||||
%EasyAlign*&
|
||||
AssertEqual 'syntax', &l:foldmethod
|
||||
|
||||
setlocal foldmethod=manual
|
||||
%EasyAlign*&
|
||||
AssertEqual 'manual', &l:foldmethod
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{}
|
||||
32 & 1.14\e1 & & 5.65\e2 & & & & 1.16\e1 & & 1.28\e1 & \\
|
||||
64 & 1.03\e1 & 0.1 & 4.98\e2 & 0.2 & & & 9.21\e2 & 0.3 & 1.02\e1 & 0.3 \\
|
||||
128 & 9.86\e2 & 0.1 & 4.69\e2 & 0.1 & & & 8.46\e2 & 0.1 & 9.45\e2 & 0.1 \\
|
||||
256 & 9.65\e2 & 0.0 & 4.59\e2 & 0.0 & & & 8.15\e2 & 0.1 & 9.11\e2 & 0.1 \\
|
||||
% 512&9.55\e2&0.0&4.56\e2&0.0&&&8.01\e2&0.0&8.96\e2&0.0\\
|
||||
1024 & 9.49\e2 & 0.0 & 4.53\e2 & 0.0 & & & 7.94\e2 & 0.0 & 8.89\e2 & 0.0 \\
|
||||
2048 & 9.47\e2 & 0.0 & 4.52\e2 & 0.0 & & & 7.91\e2 & 0.0 & 8.85\e2 & 0.0 \\
|
||||
4096 & 9.46\e2 & 0.0 & 4.51\e2 & 0.0%&&&7.90\e2&0.0&8.83\e2&0.0\\
|
||||
8192 & 9.45\e2 & 0.0 & 4.51\e2 & 0.0 & & & & & & \\
|
||||
\end{tabular}
|
||||
|
||||
Include: include/teardown.vader
|
||||
Reference in New Issue
Block a user