31 Commits

Author SHA1 Message Date
Junegunn Choi
0db4ea6132 Use virtcol in blockwise visual mode 2015-10-01 19:32:36 +09:00
Junegunn Choi
504eab0f59 Change split logic to allow advanced patterns
- \v  (Fix #67)
- \zs (Fix #55)
2015-10-01 19:26:46 +09:00
Junegunn Choi
98e0b493ac Apply filter option to substrings in blockwise-visual mode 2015-09-16 03:08:08 +09:00
Junegunn Choi
1206c65dcb Fix regular expression for = rule
Bug reported by @cvlmtg
2015-07-20 00:39:09 +09:00
Junegunn Choi
a1118be7d9 Extend default = rule to include ?=
Close #65
2015-07-15 21:57:33 +09:00
Junegunn Choi
c62d124be6 Update help file 2014-12-14 02:48:28 +09:00
Junegunn Choi
883c6b67a0 Add regression test case for #51 2014-12-10 12:01:39 +09:00
Junegunn Choi
32591ec4d4 Merge branch 'wilywampa-fixrepeat' 2014-12-10 11:53:28 +09:00
Jacob Niehus
ac9aa14ae4 Fix repeat of visual LiveEasyAlign 2014-12-09 19:41:39 -07:00
Junegunn Choi
cafe55dd65 Fix #50 - Updated shorthand notation (m -> a) 2014-12-09 15:25:44 +09:00
Junegunn Choi
6c276c37ad Add failing test case for #50 2014-12-09 15:23:46 +09:00
Junegunn Choi
1744414e7e Update README 2014-12-08 17:34:12 +09:00
Junegunn Choi
246139c57c Remove dead code (Fix #47)
Thanks to @itchyny
2014-12-01 19:26:28 +09:00
Junegunn Choi
3afd4540ed Fix #46: Remove duplicate tags 2014-12-01 01:04:04 +09:00
Junegunn Choi
2782c1d0db Fix <CTRL-P> to toggle liveness when delimiter is not entered (#44) 2014-11-30 11:34:32 +09:00
Junegunn Choi
d983381a99 Merge branch 'master' of github.com:junegunn/vim-easy-align 2014-11-30 02:03:36 +09:00
Junegunn Choi
52814ccd96 Update License 2014-11-30 02:03:13 +09:00
Junegunn Choi
aa1ba68ea0 Retain cursor position after <Plug>(EasyAlign) in visual mode 2014-11-30 02:01:52 +09:00
Junegunn Choi
b8abc366a6 Fix code indentation 2014-11-30 01:46:11 +09:00
Junegunn Choi
f6586bad39 <CTRL-P> to switch to live interactive mode (#44) 2014-11-30 01:45:27 +09:00
Junegunn Choi
44216b0a2c Do nothing when nomodifiable (#43) 2014-11-23 03:39:33 +09:00
Junegunn Choi
2595ebf933 Oops, remove duplicate line from the previous commit (#40) 2014-10-03 11:29:03 +09:00
Junegunn Choi
6bc221c285 Fix #40: Spurious undo in live interactive mode
Problem identified and patch provided by @wilywampa
2014-10-03 11:25:51 +09:00
Junegunn Choi
21697776b4 Allow recursive alignment (*, **) in blockwise-visual mode
Recursive alignment in blockwise-visual mode will align around all the
delimiters found after the start of the block. This behavior is
inconsistent with non-recursive alignment where the delimiters after the
end of the block are ignored. Making it respect the end of the block is
non-trivial and may not be intuitive as each alignment will change the
position of the delimiters inside the block and some of them will end up
beyond the scope of the block.
2014-09-13 19:54:49 +09:00
Junegunn Choi
09167c79c9 Fix travis-ci build 2014-09-08 16:30:45 +09:00
Junegunn Choi
cbb005ee71 Update the link to the default alignment rules 2014-08-14 14:29:34 +09:00
Junegunn Choi
ec15731bc9 Update README: Shorthand notation for stick_to_left option 2014-08-14 14:14:22 +09:00
Junegunn Choi
eee4735770 Update shorthand notation for stick_to_left: > to unset
- `<` == `stl1`
- `>` == `stl0`
2014-08-14 12:38:44 +09:00
Junegunn Choi
5e2a588403 Update README 2014-07-23 22:17:40 +09:00
Junegunn Choi
2fa6a040f6 Change option name and shorthand notations
- `mode_sequence` (`ms`) -> `align` (`a`)
- `stick_to_left` (`<` / `s01`)

This commit does not break backward compatibility.
`mode_sequence` is still allowed.
2014-07-23 22:15:01 +09:00
Junegunn Choi
f9a49e441d Preserve last selection when using <Plug>(EasyAlign) 2014-06-27 23:31:22 +09:00
12 changed files with 785 additions and 570 deletions

View File

@@ -2,12 +2,14 @@ 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+=.
set rtp+=after
filetype plugin indent on
syntax enable
VIMRC) -c 'Vader! test/*' > /dev/null

226
README.md
View File

@@ -1,4 +1,4 @@
vim-easy-align
vim-easy-align ![travis-ci](https://travis-ci.org/junegunn/vim-easy-align.svg?branch=master)
==============
A simple, easy-to-use Vim alignment plugin.
@@ -6,9 +6,9 @@ A simple, easy-to-use Vim alignment plugin.
Demo
----
![Screencast](https://raw.github.com/junegunn/i/master/vim-easy-align.gif)
<img src="https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align.gif" height="494" alt="Screencast">
(Too fast? Slower GIF is [here](https://raw.github.com/junegunn/i/master/vim-easy-align-slow.gif))
(Too fast? Slower GIF is [here](https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align-slow.gif))
Features
--------
@@ -22,27 +22,16 @@ Features
- Optimized for code editing
- Takes advantage of syntax highlighting feature to avoid unwanted alignments
### _"I already have a similar one. Should I switch?"_
Maybe or maybe not. See [related work](https://github.com/junegunn/vim-easy-align#related-work) section.
Installation
------------
Either [download zip file](http://www.vim.org/scripts/script.php?script_id=4520)
and extract in ~/.vim or
[use](https://github.com/tpope/vim-pathogen)
[your](https://github.com/gmarik/vundle)
[favorite](https://github.com/junegunn/vim-plug)
[plugin](https://github.com/Shougo/neobundle.vim)
[manager](https://github.com/MarcWeber/vim-addon-manager).
User your favorite plugin manager.
- [Vundle](https://github.com/gmarik/vundle)
1. Add `Plugin 'junegunn/vim-easy-align'` to .vimrc
2. Run `:PluginInstall`
- [vim-plug](https://github.com/junegunn/vim-plug)
1. Add `Plug 'junegunn/vim-easy-align'` to .vimrc
2. Run `:PlugInstall`
Using [vim-plug](https://github.com/junegunn/vim-plug):
```vim
Plug 'junegunn/vim-easy-align'
```
TL;DR - One-minute guide
------------------------
@@ -53,8 +42,8 @@ Add the following mappings to your .vimrc.
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. <Leader>aip)
nmap <Leader>a <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
```
And with the following lines of text,
@@ -71,8 +60,8 @@ try these commands:
- `v`isual-select `i`nner `p`aragraph
- Start EasyAlign command (`<Enter>`)
- Align around `=`
- `<Leader>aip=`
- Start EasyAlign command (`<Leader>a`) for `i`nner `p`aragraph
- `gaip=`
- Start EasyAlign command (`ga`) for `i`nner `p`aragraph
- Align around `=`
Notice that the commands are repeatable with `.` key if you have installed
@@ -131,13 +120,13 @@ 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. <Leader>aip)
nmap <Leader>a <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 `<Leader>a` followed by a motion or a text
1. `<Enter>` key in visual mode, or `ga` followed by a motion or a text
object to start interactive mode
1. Optional: Enter keys to select alignment mode (left, right, or center)
1. Optional: N-th delimiter (default: 1)
@@ -170,20 +159,20 @@ You can override these default rules or define your own rules with
#### Examples
| 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:s0l1` |
| `<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!**=` |
| 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
@@ -211,7 +200,7 @@ keys listed below. The meaning of each option will be described in
| `CTRL-D` | `delimiter_align` | left, center, right |
| `CTRL-U` | `ignore_unmatched` | 0, 1 |
| `CTRL-G` | `ignore_groups` | [], ['String'], ['Comment'], ['String', 'Comment'] |
| `CTRL-O` | `mode_sequence` | Input string (`/[lrc]+\*{0,2}/`) |
| `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 }` |
@@ -222,8 +211,9 @@ 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)` or
`:LiveEasyAlign` command.
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
@@ -275,21 +265,21 @@ You can even omit spaces between the arguments, so concisely (or cryptically):
Nice. But let's make it even shorter. Option values can be written in shorthand
notation.
- `:EasyAlign*/[:;]\+/s1l0`
- `: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` | `s[01]` |
| `ignore_unmatched` | `iu[01]` |
| `ignore_groups` | `ig\[.*\]` |
| `delimiter_align` | `d[lrc]` |
| `mode_sequence` | `m[lrc*]*` |
| `indentation` | `i[ksdn]` |
| 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:
@@ -345,7 +335,7 @@ Alignment options
| `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 |
| `mode_sequence` | string | | Alignment modes for multiple occurrences of delimiters |
| `align` | string | `l` | Alignment modes for multiple occurrences of delimiters |
There are 4 ways to set alignment options (from lowest precedence to highest):
@@ -354,17 +344,17 @@ There are 4 ways to set alignment options (from lowest precedence to highest):
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>` | `s[01]` | |
| `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` |
| `mode_sequence` | `CTRL-O` | `m[lrc*]*` | |
| 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
@@ -626,38 +616,38 @@ To recap:
:EasyAlign! **=
```
In addition to these, you can fine-tune alignments over multiple occurrences of
the delimiters with 'mode_sequence' option. (The option can also be set
in interactive mode with the special key `CTRL-O`)
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 = { 'mode_sequence': 'll' }
:EasyAlign = { 'align': 'll' }
" Right, left, center alignment over the 1st to 3rd occurrences of delimiters
:EasyAlign = { 'm': 'rlc' }
:EasyAlign = { 'a': 'rlc' }
" Using shorthand notation
:EasyAlign = mrlc
:EasyAlign = arlc
" Right, left, center alignment over the 2nd to 4th occurrences of delimiters
:EasyAlign 2=mrlc
:EasyAlign 2=arlc
" (*) Repeating alignments (default: l, r, or c)
" Right, left, center, center, center, center, ...
:EasyAlign *=mrlc
:EasyAlign *=arlc
" (**) Alternating alignments (default: lr or rl)
" Right, left, center, right, left, center, ...
:EasyAlign **=mrlc
:EasyAlign **=arlc
" Right, left, center, center, center, ... repeating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=mrlc*
:EasyAlign 3=arlc*
" Right, left, center, right, left, center, ... alternating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=mrlc**
:EasyAlign 3=arlc**
```
### Extending alignment rules
@@ -666,7 +656,7 @@ 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.0/autoload/easy_align.vim#L29).
[here](https://github.com/junegunn/vim-easy-align/blob/2.9.6/autoload/easy_align.vim#L32-L46).
#### Examples
@@ -739,86 +729,12 @@ Advanced examples and use cases
See [EXAMPLES.md](https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md)
for more examples.
Related work
------------
There are two well-known plugins with the same goal as that of easy-align.
- [DrChip's Alignment Tool for Vim](http://www.drchip.org/astronaut/vim/align.html) (herein will be referred to as "Align")
- [DrChip's Alignment Tool for Vim](http://www.drchip.org/astronaut/vim/align.html)
- [Tabular](https://github.com/godlygeek/tabular)
Both are great plugins with very large user bases. I actually had been a Tabular
user for a couple of years before I finally made up my mind to roll out my own.
So why would someone choose easy-align over those two?
Feature-by-feature comparison I believe is not quite useful, since a typical
user will end up using only a small subset of the features.
So I will mention just a few core benefits of easy-align.
### Ease of use
As the name implies, easy-align is *easier* to use. Its interactive mode
allows you to achieve what you want with just a few keystrokes.
The key sequence is mnemonic, so it's easy to remember and execute.
It even feels like a native Vim command!
- *Right-align*: `<Enter><Enter>`
- around the *second* occurrences: `2`
- of *whitespaces*: `<Space>`
For the simplest cases, Tabular and Align are also easy to use. But sooner or
later, you will find yourself scratching your head, trying to come up with some
complex regular expressions.
_"How am I going to align the third to the last word in each line to the right
without affecting the ones before it?"_
### Clean
easy-align doesn't clutter your workspace with mappings and global
variables. All you would need is a single mapping to the interactive EasyAlign
command, and even that is totally up to you.
### Optimized for code editing
easy-align by default performs syntax-aware alignment, which is invaluable
when editing codes.
Try to come up with a regular expression to correctly format the following code
snippet. With easy-align under default configuration and a mapping, it can
be done with just two keystrokes: `<Enter>:`
```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"
};
```
(To be fair, Align also can be configured to consider syntax highlighting with
`g:AlignSkip` function reference which should point to a custom function that
looks up the syntax group of a character on a certain position)
### Thoroughly tested
Virtually every aspect of easy-align is being tested with a comprehensive
set of test cases using [Vader.vim](https://github.com/junegunn/vader.vim).
### "Okay. So should I switch?"
Maybe, but I can't really say. I have no ambition to make easy-align
an absolute superior to the others. For some cases, easy-align works better
than the others, but for some other cases, Tabular or Align.vim might be a
better choice.
So try it yourself and see if it works for you!
Author
------

View File

@@ -1,4 +1,4 @@
" Copyright (c) 2013 Junegunn Choi
" Copyright (c) 2014 Junegunn Choi
"
" MIT License
"
@@ -31,7 +31,7 @@ set cpo&vim
let s:easy_align_delimiters_default = {
\ ' ': { 'pattern': ' ', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 },
\ '=': { 'pattern': '===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.-]\?=[#?]\?',
\ '=': { 'pattern': '===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.?-]\?=[#?]\?',
\ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
\ ':': { 'pattern': ':', 'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 },
\ ',': { 'pattern': ',', 'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 },
@@ -51,7 +51,8 @@ let s:known_options = {
\ 'margin_left': [0, 1], 'margin_right': [0, 1], 'stick_to_left': [0],
\ 'left_margin': [0, 1], 'right_margin': [0, 1], 'indentation': [1],
\ 'ignore_groups': [3 ], 'ignore_unmatched': [0 ], 'delimiter_align': [1],
\ 'mode_sequence': [1 ], 'ignores': [3], 'filter': [1]
\ 'mode_sequence': [1 ], 'ignores': [3], 'filter': [1],
\ 'align': [1 ]
\ }
let s:option_values = {
@@ -65,7 +66,8 @@ let s:shorthand = {
\ 'margin_left': 'lm', 'margin_right': 'rm', 'stick_to_left': 'stl',
\ 'left_margin': 'lm', 'right_margin': 'rm', 'indentation': 'idt',
\ 'ignore_groups': 'ig', 'ignore_unmatched': 'iu', 'delimiter_align': 'da',
\ 'mode_sequence': 'm', 'ignores': 'ig', 'filter': 'f'
\ 'mode_sequence': 'a', 'ignores': 'ig', 'filter': 'f',
\ 'align': 'a'
\ }
if exists("*strdisplaywidth")
@@ -144,7 +146,7 @@ endfunction
function! s:echon(l, n, r, d, o, warn)
let tokens = [
\ ['Function', ':EasyAlign'],
\ ['Function', s:live ? ':LiveEasyAlign' : ':EasyAlign'],
\ ['ModeMsg', get(s:mode_labels, a:l, a:l)],
\ ['None', ' ']]
@@ -227,8 +229,9 @@ function! s:normalize_options(opts)
let v = a:opts[k]
let k = s:fuzzy_lu(k)
" Backward-compatibility
if k == 'margin_left' | let k = 'left_margin' | endif
if k == 'margin_right' | let k = 'right_margin' | endif
if k == 'margin_left' | let k = 'left_margin' | endif
if k == 'margin_right' | let k = 'right_margin' | endif
if k == 'mode_sequence' | let k = 'align' | endif
let ret[k] = v
unlet v
endfor
@@ -261,11 +264,8 @@ function! s:split_line(line, nth, modes, cycle, fc, lc, pattern, stick_to_left,
\ strpart(getline(a:line), a:fc - 1, a:lc - a:fc + 1) :
\ strpart(getline(a:line), a:fc - 1)
let idx = 0
" Do not allow \zs
" 1: whole match
" 2: token
" 3: delimiter
let pattern = '^\(\(.\{-}\s*\)\(' .a:pattern. '\)\s' . (a:stick_to_left ? '*' : '\{-}') . '\)'
let nomagic = match(a:pattern, '\\v') > match(a:pattern, '\C\\[mMV]')
let pattern = '^.\{-}\s*\zs\('.a:pattern.(nomagic ? ')' : '\)')
let tokens = []
let delims = []
@@ -274,18 +274,22 @@ function! s:split_line(line, nth, modes, cycle, fc, lc, pattern, stick_to_left,
let token = ''
let phantom = 0
while 1
let matches = matchlist(string, pattern, idx)
let matchidx = match(string, pattern, idx)
" No match
if empty(matches) | break | endif
if matchidx < 0 | break | endif
let matchend = matchend(string, pattern, idx)
let spaces = matchstr(string, '\s'.(a:stick_to_left ? '*' : '\{-}'), matchend + (matchidx == matchend))
" Match, but empty delimiter
if empty(matches[1])
" Match, but empty
if len(spaces) + matchend - idx == 0
let char = strpart(string, idx, 1)
if empty(char) | break | endif
let [match, part, delim] = [char, char, '']
" Match
else
let [match, part, delim] = matches[1 : 3]
let match = strpart(string, idx, matchend - idx + len(spaces))
let part = strpart(string, idx, matchidx - idx)
let delim = strpart(string, matchidx, matchend - matchidx)
endif
let ignorable = s:highlighted_as(a:line, idx + len(part) + a:fc, a:ignore_groups)
@@ -355,9 +359,10 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
" Phase 1
for line in range(a:fl, a:ll)
if f == 1 && getline(line) !~ fx
let snip = a:lc > 0 ? getline(line)[a:fc-1 : a:lc-1] : getline(line)
if f == 1 && snip !~ fx
continue
elseif f == -1 && getline(line) =~ fx
elseif f == -1 && snip =~ fx
continue
endif
@@ -614,7 +619,7 @@ function! s:shift_opts(opts, key, vals)
endif
endfunction
function! s:interactive(range, modes, n, d, opts, rules, vis, live)
function! s:interactive(range, modes, n, d, opts, rules, vis, bvis)
let mode = s:shift(a:modes, 1)
let n = a:n
let d = a:d
@@ -633,11 +638,11 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
let undo = 0
let rdrw = 1
endif
if a:live && !empty(d)
let output = s:process(a:range, mode, n, d, s:normalize_options(opts), regx, a:rules, 0)
if s:live && !empty(d)
let output = s:process(a:range, mode, n, d, s:normalize_options(opts), regx, a:rules, a:bvis)
let &undolevels = &undolevels " Break undo block
call s:update_lines(output.todo)
let undo = 1
let undo = !empty(output.todo)
let rdrw = 1
endif
if rdrw
@@ -668,8 +673,8 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
endif
elseif c == 13 " Enter key
let mode = s:shift(a:modes, 1)
if has_key(opts, 'm')
let opts.m = mode . strpart(opts.m, 1)
if has_key(opts, 'a')
let opts.a = mode . strpart(opts.a, 1)
endif
elseif ch == '-'
if empty(n) | let n = '-'
@@ -710,6 +715,17 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
call s:shift_opts(opts, 'iu', vals['ignore_unmatched'])
elseif ch == "\<C-G>"
call s:shift_opts(opts, 'ig', vals['ignore_groups'])
elseif ch == "\<C-P>"
if s:live
if !empty(d)
let ch = d
break
else
let s:live = 0
endif
else
let s:live = 1
endif
elseif c == "\<Left>"
let opts['stl'] = 1
let opts['lm'] = 0
@@ -723,18 +739,18 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
silent! call remove(opts, 'stl')
silent! call remove(opts, 'lm')
silent! call remove(opts, 'rm')
elseif ch == "\<C-O>"
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode), a:vis))
elseif ch == "\<C-A>" || ch == "\<C-O>"
let modes = tolower(s:input("Alignment ([lrc...][[*]*]): ", get(opts, 'a', mode), a:vis))
if match(modes, '^[lrc]\+\*\{0,2}$') != -1
let opts['m'] = modes
let opts['a'] = modes
let mode = modes[0]
while mode != s:shift(a:modes, 1)
endwhile
else
silent! call remove(opts, 'm')
silent! call remove(opts, 'a')
endif
elseif ch == "\<C-_>" || ch == "\<C-X>"
if a:live && regx && !empty(d)
if s:live && regx && !empty(d)
break
endif
@@ -743,7 +759,7 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
if !empty(ch) && s:valid_regexp(ch)
let regx = 1
let d = ch
if !a:live | break | endif
if !s:live | break | endif
else
let warn = 'Invalid regular expression: '.ch
endif
@@ -767,7 +783,10 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
if empty(d)
if has_key(a:rules, ch)
let d = ch
if !a:live
if !s:live
if a:vis
execute "normal! gv\<esc>"
endif
break
endif
else
@@ -786,9 +805,11 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
endif
endif
endwhile
if a:live
if s:live
let copts = call('s:summarize', output.summarize)
let s:live = 0
let g:easy_align_last_command = s:echon('', n, regx, d, copts, '')
let s:live = 1
end
return [mode, n, ch, opts, regx]
endfunction
@@ -811,8 +832,8 @@ endfunction
let s:shorthand_regex =
\ '\s*\%('
\ .'\(lm\?[0-9]\+\)\|\(rm\?[0-9]\+\)\|\(iu[01]\)\|\(s\%(tl\)\?[01]\)\|'
\ .'\(da\?[clr]\)\|\(ms\?[lrc*]\+\)\|\(i\%(dt\)\?[kdsn]\)\|\([gv]/.*/\)\|\(ig\[.*\]\)'
\ .'\(lm\?[0-9]\+\)\|\(rm\?[0-9]\+\)\|\(iu[01]\)\|\(\%(s\%(tl\)\?[01]\)\|[<>]\)\|'
\ .'\(da\?[clr]\)\|\(\%(ms\?\|a\)[lrc*]\+\)\|\(i\%(dt\)\?[kdsn]\)\|\([gv]/.*/\)\|\(ig\[.*\]\)'
\ .'\)\+\s*$'
function! s:parse_shorthand_opts(expr)
@@ -826,9 +847,8 @@ function! s:parse_shorthand_opts(expr)
call s:exit("Invalid expression: ". a:expr)
else
let match = matchlist(expr, regex)
if empty(match) | break | endif
for m in filter(match[ 1 : -1 ], '!empty(v:val)')
for key in ['lm', 'rm', 'l', 'r', 'stl', 's', 'iu', 'da', 'd', 'ms', 'm', 'ig', 'i', 'g', 'v']
for key in ['lm', 'rm', 'l', 'r', 'stl', 's', '<', '>', 'iu', 'da', 'd', 'ms', 'm', 'ig', 'i', 'g', 'v', 'a']
if stridx(tolower(m), key) == 0
let rest = strpart(m, len(key))
if key == 'i' | let key = 'idt' | endif
@@ -837,7 +857,7 @@ function! s:parse_shorthand_opts(expr)
let key = 'f'
endif
if key == 'idt' || index(['d', 'f', 'm'], key[0]) >= 0
if key == 'idt' || index(['d', 'f', 'm', 'a'], key[0]) >= 0
let opts[key] = rest
elseif key == 'ig'
try
@@ -850,6 +870,8 @@ function! s:parse_shorthand_opts(expr)
catch
call s:exit("Invalid ignore_groups: ". a:expr)
endtry
elseif key =~ '[<>]'
let opts['stl'] = key == '<'
else
let opts[key] = str2nr(rest)
endif
@@ -955,9 +977,9 @@ function! s:alternating_modes(mode)
endfunction
function! s:update_lines(todo)
for [line, content] in items(a:todo)
call setline(line, s:rtrim(content))
endfor
for [line, content] in items(a:todo)
call setline(line, s:rtrim(content))
endfor
endfunction
function! s:parse_nth(n)
@@ -1025,19 +1047,18 @@ function! s:process(range, mode, n, ch, opts, regexp, rules, bvis)
let [nth, recur] = s:parse_nth(a:n)
let dict = s:build_dict(a:rules, a:ch, a:regexp, a:opts)
let [mode_sequence, recur] = s:build_mode_sequence(
\ get(dict, 'mode_sequence', recur == 2 ? s:alternating_modes(a:mode) : a:mode),
\ get(dict, 'align', recur == 2 ? s:alternating_modes(a:mode) : a:mode),
\ recur)
if recur && a:bvis
call s:exit('Recursive alignment is not supported in blockwise-visual mode')
endif
let ve = &virtualedit
set ve=all
let args = [
\ {}, split(mode_sequence, '\zs'),
\ {}, {}, a:range[0], a:range[1],
\ a:bvis ? min([col("'<"), col("'>")]) : 1,
\ a:bvis ? max([col("'<"), col("'>")]) : 0,
\ a:bvis ? min([virtcol("'<"), virtcol("'>")]) : 1,
\ (!recur && a:bvis) ? max([virtcol("'<"), virtcol("'>")]) : 0,
\ nth, recur, dict ]
let &ve = ve
while len(args) > 1
let args = call('s:do_align', args)
endwhile
@@ -1050,11 +1071,11 @@ endfunction
function s:summarize(opts, recur, mode_sequence)
let copts = s:compact_options(a:opts)
let nbmode = s:interactive_modes(0)[0]
if !has_key(copts, 'm') && (
if !has_key(copts, 'a') && (
\ (a:recur == 2 && s:alternating_modes(nbmode) != a:mode_sequence) ||
\ (a:recur != 2 && (a:mode_sequence[0] != nbmode || len(a:mode_sequence) > 1))
\ )
call extend(copts, { 'm': a:mode_sequence })
call extend(copts, { 'a': a:mode_sequence })
endif
return copts
endfunction
@@ -1072,10 +1093,7 @@ function! s:align(bang, live, visualmode, first_line, last_line, expr)
let range = [a:first_line, a:last_line]
let modes = s:interactive_modes(a:bang)
let mode = modes[0]
if bvis && a:live
call s:exit('Live mode is not supported in blockwise-visual mode')
endif
let s:live = a:live
let rules = s:easy_align_delimiters_default
if exists('g:easy_align_delimiters')
@@ -1089,11 +1107,11 @@ function! s:align(bang, live, visualmode, first_line, last_line, expr)
try
if bypass_fold | let &l:foldmethod = 'manual' | endif
if empty(n) && empty(ch) || a:live
let [mode, n, ch, opts, regexp] = s:interactive(range, copy(modes), n, ch, opts, rules, vis, a:live)
if empty(n) && empty(ch) || s:live
let [mode, n, ch, opts, regexp] = s:interactive(range, copy(modes), n, ch, opts, rules, vis, bvis)
endif
if !a:live
if !s:live
let output = s:process(range, mode, n, ch, s:normalize_options(opts), regexp, rules, bvis)
call s:update_lines(output.todo)
let copts = call('s:summarize', output.summarize)

View File

@@ -1,51 +1,43 @@
easy-align.txt vim-easy-align Last change: May 31 2014
VIM-EASY-ALIGN - TABLE OF CONTENTS *easyalign* *easy-align* *easy-align-toc*
easy-align.txt easy-align Last change: December 14 2014
EASY-ALIGN - TABLE OF CONTENTS *easyalign* *easy-align* *easy-align-toc*
==============================================================================
Demo |easy-align-1|
Features |easy-align-2|
"I already have a similar one. Should I switch?" |easy-align-2-1|
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|
Ease of use |easy-align-9-1|
Clean |easy-align-9-2|
Optimized for code editing |easy-align-9-3|
Thoroughly tested |easy-align-9-4|
"Okay. So should I switch?" |easy-align-9-5|
Author |easy-align-10|
License |easy-align-11|
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|
VIM-EASY-ALIGN *vim-easy-align*
@@ -58,11 +50,12 @@ A simple, easy-to-use Vim alignment plugin.
DEMO *easy-align-demo*
==============================================================================
Screencast: https://raw.github.com/junegunn/i/master/vim-easy-align.gif
Screencast:
https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align.gif
(Too fast? Slower GIF is {here}{1})
{1} https://raw.github.com/junegunn/i/master/vim-easy-align-slow.gif
{1} https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align-slow.gif
*easy-align-2*
@@ -70,42 +63,27 @@ FEATURES *easy-align-features*
==============================================================================
- Easy to use
- Comes with a predefined set of alignment rules
- Provides a fast and intuitive interface
- 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
- You can define your own rules
- Supports arbitrary regular expressions
- Optimized for code editing
- Takes advantage of syntax highlighting feature to avoid unwanted alignments
< "I already have a similar one. Should I switch?" >__________________________~
*easy-align-i-already-have-a-similar-one-should-i-switch*
*easy-align-2-1*
Maybe or maybe not. See related work (|easy-align-related-work|) section.
- Takes advantage of syntax highlighting feature to avoid unwanted
alignments
*easy-align-3*
INSTALLATION *easy-align-installation*
==============================================================================
Either {download zip file}{2} and extract in ~/.vim or {use}{3} {your}{4}
{favorite}{5} {plugin}{6} {manager}{7}.
User your favorite plugin manager.
{2} http://www.vim.org/scripts/script.php?script_id=4520
{3} https://github.com/tpope/vim-pathogen
{4} https://github.com/gmarik/vundle
{5} https://github.com/junegunn/vim-plug
{6} https://github.com/Shougo/neobundle.vim
{7} https://github.com/MarcWeber/vim-addon-manager
- {Vundle}{4}
- Add `Plugin 'junegunn/vim-easy-align'` to .vimrc
- Run `:PluginInstall`
- {vim-plug}{5}
- Add `Plug 'junegunn/vim-easy-align'` to .vimrc
- Run `:PlugInstall`
Using {vim-plug}{2}:
>
Plug 'junegunn/vim-easy-align'
<
{2} https://github.com/junegunn/vim-plug
*easy-align-4*
@@ -113,12 +91,14 @@ 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. <Leader>aip)
nmap <Leader>a <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
<
And with the following lines of text,
>
@@ -129,19 +109,19 @@ And with the following lines of text,
try these commands:
- vip<Enter>=
- `v`isual-select `i`nner `p`aragraph
- Start EasyAlign command (<Enter>)
- Align around `=`
- <Leader>aip=
- Start EasyAlign command (<Leader>a) for `i`nner `p`aragraph
- Align around `=`
- `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}{8}. Install {visualrepeat}{9} as well if you want to repeat in
{repeat.vim}{3}. Install {visualrepeat}{4} as well if you want to repeat in
visual mode.
{8} https://github.com/tpope/vim-repeat
{9} https://github.com/vim-scripts/visualrepeat
{3} https://github.com/tpope/vim-repeat
{4} https://github.com/vim-scripts/visualrepeat
*easy-align-5*
@@ -157,8 +137,8 @@ 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 `,`.
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.
@@ -171,20 +151,22 @@ several options, you can just type in a single character.
There are two ways to use easy-align.
1. Using <Plug> mappings~
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>(EasyAlign)* *<Plug>(LiveEasyAlign)*
*<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
----------------------+--------+-----------------------------------------------------
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~
@@ -196,12 +178,16 @@ The recommended method is to use <Plug> mappings as described earlier.
If you prefer command-line or do not want to start interactive mode, you can
use `:EasyAlign` command instead.
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]`
*: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 >__________________________________________________________~
@@ -214,65 +200,71 @@ 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. <Leader>aip)
nmap <Leader>a <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 <Leader>a followed by a motion or a text object
to start interactive mode
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> , `=`, `:`, `.`, `|`, `&`, `,`)
- `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~
------------- | --------------------------------------------------------------------
--------------+--------------------------------------------------------------------
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 `\\` )
`=` | 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
<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
(|easy-align-extending-alignment-rules|).
`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:s0l1
<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!**=
------------------+------------------------------------+--------------------
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~
@@ -280,36 +272,40 @@ 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:
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]\+`
- `[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 (|easy-align-alignment-options|).
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-O | `mode_sequence` | 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 }`
--------+--------------------+---------------------------------------------------
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 >_____________________________________________________~
@@ -320,15 +316,14 @@ 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.
*:LiveEasyAlign*
Live interactive mode can be started with either <Plug>(LiveEasyAlign) or
`:LiveEasyAlign` command.
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.
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 >______________________________________________________~
@@ -352,14 +347,14 @@ Instead of starting interactive mode, you can use declarative, non-interactive
:EasyAlign */[:;]\+/
:EasyAlign **/[:;]\+/
<
A command can end with alignment options, each of which will be discussed in
detail later (|easy-align-alignment-options|), in Vim dictionary format.
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:
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
@@ -372,24 +367,26 @@ 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.
Nice. But let's make it even shorter. Option values can be written in
shorthand notation.
- `:EasyAlign*/[:;]\+/s1l0`
- `: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` | `s[01]`
`ignore_unmatched` | `iu[01]`
`ignore_groups` | `ig\[.*\]`
`delimiter_align` | `d[lrc]`
`mode_sequence` | `m[lrc*]*`
`indentation` | `i[ksdn]`
-------------------+-----------
`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:
@@ -398,7 +395,9 @@ follows:
- `*`
- <Left>
- CTRL-X
- `[:;]\+`
- `[:;]\+`
{6} https://github.com/junegunn/vim-easy-align#alignment-options
< Partial alignment in blockwise-visual mode >________________________________~
@@ -408,7 +407,8 @@ follows:
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.
Consider the following case where you want to align text around `=>`
operators.
>
my_hash = { :a => 1,
:aa => 2,
@@ -416,8 +416,8 @@ Consider the following case where you want to align text around `=>` operators.
<
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>= .
blockwise-visual mode (CTRL-V), and select the text around`=>` operators, then
press <Enter>=.
>
my_hash = { :a => 1,
:aa => 2,
@@ -436,19 +436,21 @@ ALIGNMENT OPTIONS *easy-align-alignment-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
`mode_sequence` | string | | Alignment modes for multiple occurrences of delimiters
-------------------+---------+-----------------------+--------------------------------------------------------
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):
@@ -460,17 +462,19 @@ There are 4 ways to set alignment options (from lowest precedence to highest):
*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> | `s[01]` |
`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`
`mode_sequence` | CTRL-O | `m[lrc*]*` |
-------------------+-----------------+-------------+--------------------------------
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 >___________________________________________________________~
@@ -481,14 +485,15 @@ 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/'}`
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)
(You don't need to escape "/'s in the regular expression)
Examples~
*easy-align-examples-2*
*easy-align-6-2-1*
>
" Start interactive mode with filter option set to g/hello/
@@ -556,15 +561,18 @@ For example if you set `ignore_groups` option to be an empty list, you get
'grape: fruits': 3
}
<
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.
< Ignoring unmatched lines >__________________________________________________~
*easy-align-ignoring-unmatched-lines*
*easy-align-6-4*
`ignore_unmatched` option determines how EasyAlign command processes lines that
do not have N-th delimiter.
`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
@@ -619,8 +627,8 @@ Then we get,
*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.
`delimiter_align` option determines how matched delimiters of different
lengths are aligned.
>
apple = 1
banana += apple
@@ -700,8 +708,8 @@ In interactive mode, you can change the option value with CTRL-I key.
*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.
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:
>
@@ -723,37 +731,37 @@ To recap:
" 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 'mode_sequence' option. (The option can also be set in
interactive mode with the special key CTRL-O)
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 = { 'mode_sequence': 'll' }
:EasyAlign = { 'align': 'll' }
" Right, left, center alignment over the 1st to 3rd occurrences of delimiters
:EasyAlign = { 'm': 'rlc' }
:EasyAlign = { 'a': 'rlc' }
" Using shorthand notation
:EasyAlign = mrlc
:EasyAlign = arlc
" Right, left, center alignment over the 2nd to 4th occurrences of delimiters
:EasyAlign 2=mrlc
:EasyAlign 2=arlc
" (*) Repeating alignments (default: l, r, or c)
" Right, left, center, center, center, center, ...
:EasyAlign *=mrlc
:EasyAlign *=arlc
" (**) Alternating alignments (default: lr or rl)
" Right, left, center, right, left, center, ...
:EasyAlign **=mrlc
:EasyAlign **=arlc
" Right, left, center, center, center, ... repeating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=mrlc*
:EasyAlign 3=arlc*
" Right, left, center, right, left, center, ... alternating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=mrlc**
:EasyAlign 3=arlc**
<
< Extending alignment rules >_________________________________________________~
@@ -763,19 +771,21 @@ interactive mode with the special key CTRL-O)
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}{10}.
You may refer to the definitions of the default alignment rules {here}{7}.
{10} https://github.com/junegunn/vim-easy-align/blob/2.9.0/autoload/easy_align.vim#L29
{7} https://github.com/junegunn/vim-easy-align/blob/2.9.6/autoload/easy_align.vim#L32-L46
Examples~
*easy-align-examples-3*
*easy-align-6-8-1*
>
let g:easy_align_delimiters = {
\ '>': { 'pattern': '>>\|=>\|>' },
\ '/': { 'pattern': '//\+\|/\*\|\*/', 'ignore_groups': ['String'] },
\ '#': { 'pattern': '#\+', 'ignore_groups': ['String'], 'delimiter_align': 'l' },
\ '/': {
\ 'pattern': '//\+\|/\*\|\*/',
\ 'delimiter_align': 'l',
\ 'ignore_groups': ['!Comment'] },
\ ']': {
\ 'pattern': '[[\]]',
\ 'left_margin': 0,
@@ -789,8 +799,8 @@ Examples~
\ 'stick_to_left': 0
\ },
\ 'd': {
\ 'pattern': ' \(\S\+\s*[;=]\)\@=',
\ 'left_margin': 0,
\ 'pattern': ' \(\S\+\s*[;=]\)\@=',
\ 'left_margin': 0,
\ 'right_margin': 0
\ }
\ }
@@ -807,16 +817,16 @@ OTHER OPTIONS *easy-align-other-options*
*g:easy_align_bypass_fold*
{It is reported}{11} that 'foldmethod' value of `expr` or `syntax` can
{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.
{11} https://github.com/junegunn/vim-easy-align/issues/14
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*
@@ -828,15 +838,14 @@ 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
- Left, Right, Center
- `:EasyAlign!`
- Right, Left, Center
- 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*
*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']
@@ -846,115 +855,29 @@ settings as follows.
ADVANCED EXAMPLES AND USE CASES *easy-align-advanced-examples-and-use-cases*
==============================================================================
See {EXAMPLES.md}{12} for more examples.
See {EXAMPLES.md}{9} for more examples.
{12} https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md
{9} https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md
*easy-align-9*
RELATED WORK *easy-align-related-work*
==============================================================================
There are two well-known plugins with the same goal as that of easy-align.
- {DrChip's Alignment Tool for Vim}{10}
- {Tabular}{11}
- {DrChip's Alignment Tool for Vim}{13} (herein will be referred to as "Align")
- {Tabular}{14}
Both are great plugins with very large user bases. I actually had been a
Tabular user for a couple of years before I finally made up my mind to roll out
my own.
So why would someone choose easy-align over those two?
Feature-by-feature comparison I believe is not quite useful, since a typical
user will end up using only a small subset of the features. So I will mention
just a few core benefits of easy-align.
< Ease of use >_______________________________________________________________~
*easy-align-ease-of-use*
*easy-align-9-1*
As the name implies, easy-align is easier to use. Its interactive mode allows
you to achieve what you want with just a few keystrokes. The key sequence is
mnemonic, so it's easy to remember and execute. It even feels like a native Vim
command!
- Right-align: <Enter><Enter>
- around the second occurrences: `2`
- of whitespaces: <Space>
For the simplest cases, Tabular and Align are also easy to use. But sooner or
later, you will find yourself scratching your head, trying to come up with some
complex regular expressions.
"How am I going to align the third to the last word in each line to the right
without affecting the ones before it?"
< Clean >_____________________________________________________________________~
*easy-align-clean*
*easy-align-9-2*
easy-align doesn't clutter your workspace with mappings and global variables.
All you would need is a single mapping to the interactive EasyAlign command,
and even that is totally up to you.
< Optimized for code editing >________________________________________________~
*easy-align-optimized-for-code-editing*
*easy-align-9-3*
easy-align by default performs syntax-aware alignment, which is invaluable when
editing codes.
Try to come up with a regular expression to correctly format the following code
snippet. With easy-align under default configuration and a mapping, it can be
done with just two keystrokes: <Enter>:
>
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"
};
<
(To be fair, Align also can be configured to consider syntax highlighting with
`g:AlignSkip` function reference which should point to a custom function that
looks up the syntax group of a character on a certain position)
< Thoroughly tested >_________________________________________________________~
*easy-align-thoroughly-tested*
*easy-align-9-4*
Virtually every aspect of easy-align is being tested with a comprehensive set
of test cases using {Vader.vim}{15}.
{15} https://github.com/junegunn/vader.vim
< "Okay. So should I switch?" >_______________________________________________~
*easy-align-okay-so-should-i-switch*
*easy-align-9-5*
Maybe, but I can't really say. I have no ambition to make easy-align an
absolute superior to the others. For some cases, easy-align works better than
the others, but for some other cases, Tabular or Align.vim might be a better
choice.
So try it yourself and see if it works for you!
{10} http://www.drchip.org/astronaut/vim/align.html
{11} https://github.com/godlygeek/tabular
*easy-align-10*
AUTHOR *easy-align-author*
==============================================================================
{Junegunn Choi}{16}
{Junegunn Choi}{12}
{16} https://github.com/junegunn
{12} https://github.com/junegunn
*easy-align-11*

View File

@@ -1,4 +1,4 @@
" Copyright (c) 2013 Junegunn Choi
" Copyright (c) 2014 Junegunn Choi
"
" MIT License
"
@@ -75,30 +75,31 @@ function! s:set_repeat()
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 tail = "\<C-c>"
if a:type == 'line'
silent execute "normal! '[V']".tail
elseif a:type == 'block'
silent execute "normal! `[\<C-V>`]".tail
else
silent execute "normal! `[v`]".tail
endif
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 "'<,'>". g:easy_align_last_command
execute range . g:easy_align_last_command
else
'<,'>call easy_align#align('<bang>' == '!', a:live, vmode, '')
execute range . "call easy_align#align('<bang>' == '!', a:live, vmode, '')"
end
call s:set_repeat()
finally

22
test/blockwise.vader Normal file
View 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

View File

@@ -40,14 +40,21 @@ Expect:
apple;:;;banana :: cake
data ;; exchange:;::format
Execute (shorthand notation of mode_sequence and margin):
Execute (DEPRECATED: shorthand notation of mode_sequence and margin):
%EasyAlign/[:;]\+/mrc*l2r2
Expect:
apple ;:;; banana :: cake
data ;; exchange :;:: format
Execute (deep indentation):
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*
@@ -55,6 +62,14 @@ 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
@@ -62,6 +77,20 @@ 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':'>'}

13
test/extra.vader Normal file
View 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

View File

@@ -139,4 +139,111 @@ Expect:
## 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

View File

@@ -30,3 +30,9 @@ Execute (Clean up test environment):
nmap <leader>A <Plug>(EasyAlign)
vmap <leader>. <Plug>(EasyAlignRepeat)
silent! call plug#load('vim-easy-align')
Before:
After:
Given:

View File

@@ -1,3 +1,4 @@
Execute:
Given:
Execute (Restoring test environment):
Restore

View File

@@ -19,6 +19,17 @@ Expect:
111 22 333 444 55555 6666 7 88888
1111 2 33 444 555 66 777 8
Do (left-align / cursor position retained):
vGww
\<Enter>
*\<Space>D
Expect:
1 22222 33 444 555 6666 7 888
11 222 3333 4 55 6666 77 888
111 22 333 444 55555 6666 7 88888
1111 2
Do (left-align using operator map):
\<Space>Aip*\<Space>
@@ -485,6 +496,56 @@ Expect:
|)batch_size(|) Fixnum(|)nil (|)number of maximum items to be assigned at once(|
|)logger (|) Logger(|)nil (|) logger instance for debug logs(|
Do (Switching to live interactive mode):
vip\<Enter>
* Switch to live interactive mode
\<C-P>
|
\<C-L><\<Enter>
\<C-R>>\<Enter>
***
**
\<BS>\<BS>\<BS>
**|\<Enter>|
Expect:
|>Option <|> Type<|>Default<|> Description<|
|>-- <|> --<|>-- <|> --<|
|>threads <|> Fixnum<|>1 <|> number of threads in the thread pool<|
|>queues <|> Fixnum<|>1 <|> number of concurrent queues<|
|>queue_size<|> Fixnum<|>1000 <|> size of each queue<|
|>interval <|>Numeric<|>0 <|> dispatcher interval for batch processing<|
|>batch <|>Boolean<|>false <|> enables batch processing mode<|
|>batch_size<|> Fixnum<|>nil <|>number of maximum items to be assigned at once<|
|>logger <|> Logger<|>nil <|> logger instance for debug logs<|
Do (Toggling live interactive mode (delimiter entered)):
vip\<Enter>
* Enable live mode
\<C-P>
|*
* Disable live mode
\<C-P>
gg2jdG
Expect:
| Option | Type | Default | Description |
| -- | -- | -- | -- |
Do (Toggling live interactive mode (delimiter not entered)):
vip\<Enter>
* Enable live mode
\<C-P>
\<Enter>
* Disable live mode
\<C-P>
*|
gg2jdG
Expect:
| Option | Type | Default | Description |
| -- | -- | -- | -- |
Do (live interactive mode!):
vip\<Space>r\<Enter>
|
@@ -758,7 +819,7 @@ Expect ruby:
dddddd /= 123
gg <=> ee
Do (Alignment using mode_sequence, delimiter_align):
Do (DEPRECATED: Alignment using mode_sequence, delimiter_align):
vip\<Enter>\<C-O>\<Backspace>cr*\<Enter>\<C-D>=
Expect ruby:
@@ -787,7 +848,37 @@ Expect ruby:
dddddd /= 123
gg <=> ee
Do (mode_sequence starting from 2nd, delimiter_align = center):
Do (Alignment using align, delimiter_align):
vip\<Enter>\<C-A>\<Backspace>cr*\<Enter>\<C-D>=
Expect ruby:
a =
a = 1
bbbb .= 2
ccccccc = 3
ccccccccccccccc
ddd = #
eeee === eee = eee = eee = f
fff = ggg += gg &&= gg
g != hhhhhhhh == # 8
i := 5
i %= 5
i *= 5
j =~ 5
j >= 5
aa => 123
aa <<= 123
aa >>= 123
bbb => 123
c => 1233123
d => 123
dddddd &&= 123
dddddd ||= 123
dddddd /= 123
gg <=> ee
Do (DEPRECATED: mode_sequence starting from 2nd, delimiter_align = center):
vip\<Enter>\<C-O>\<Backspace>rc**\<Enter>\<C-D>\<C-D>2=
Expect ruby:
@@ -816,6 +907,35 @@ Expect ruby:
dddddd /= 123
gg <=> ee
Do (align starting from 2nd, delimiter_align = center):
vip\<Enter>\<C-A>\<Backspace>rc**\<Enter>\<C-D>\<C-D>2=
Expect ruby:
a =
a = 1
bbbb .= 2
ccccccc = 3
ccccccccccccccc
ddd = #
eeee === eee = eee = eee = f
fff = ggg += gg &&= gg
g != hhhhhhhh == # 8
i := 5
i %= 5
i *= 5
j =~ 5
j >= 5
aa => 123
aa <<= 123
aa >>= 123
bbb => 123
c => 1233123
d => 123
dddddd &&= 123
dddddd ||= 123
dddddd /= 123
gg <=> ee
Do (around all =s, do not ignore unmatched):
vip\<Enter>\<C-U>
\<C-L>0\<Enter>
@@ -1415,6 +1535,63 @@ Expect:
bbbbb=bbbbb=bbbbb
aaa = aaa = aaa
Given clojure (filter with blockwise-visual mode):
(let [a 1
bbb 2
ccccc (range
10 20)]
(prn [a bbb ccccc]))
Do (filter with blockwise-visual mode):
f[
vi[
\<C-V>
\<Enter>
\<C-F>g/^\S\<Enter>
\<Space>
Expect clojure:
(let [a 1
bbb 2
ccccc (range
10 20)]
(prn [a bbb ccccc]))
Given clojure:
{:user {:plugins [[cider/cider-nrepl "0.9.1"]
[lein-kibit "0.0.8"]
[lein-licenses "0.1.1"]
[lein-marginalia "0.8.0"] ; lein marg
[codox "0.8.13"] ; lein doc
[com.jakemccrary/lein-test-refresh "0.10.0"] ; lein test-refresh
[lein-pprint "1.1.2"]
[lein-exec "0.3.5"]
[jonase/eastwood "0.2.1"]]
:dependencies [[slamhound "1.5.5"]]
:aliases {"slamhound" ["run" "-m" "slam.hound"]}
:signing {:gpg-key "FEF9C627"}}}
Do (Virtual column should be used in blockwise-visual mode):
f[
vi[
\<C-V>
$20l
\<Enter>\<Space>
Expect clojure:
{:user {:plugins [[cider/cider-nrepl "0.9.1"]
[lein-kibit "0.0.8"]
[lein-licenses "0.1.1"]
[lein-marginalia "0.8.0"] ; lein marg
[codox "0.8.13"] ; lein doc
[com.jakemccrary/lein-test-refresh "0.10.0"] ; lein test-refresh
[lein-pprint "1.1.2"]
[lein-exec "0.3.5"]
[jonase/eastwood "0.2.1"]]
:dependencies [[slamhound "1.5.5"]]
:aliases {"slamhound" ["run" "-m" "slam.hound"]}
:signing {:gpg-key "FEF9C627"}}}
###########################################################
Given (hard-tab indentation (#19)):
@@ -1568,7 +1745,7 @@ Do (Blockwise-visual-operator is also repeatable):
f1
4j
\<Enter>:
7G
7G0
fa
.