47 Commits

Author SHA1 Message Date
j-xella
9815a55dbc Resolve syntax highlighting group in neovim/treesitter (#160)
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
2024-04-13 12:21:42 +09:00
Michael Gaffney
12dd631697 Allow 'easy-align.txt' to be listed in the LOCAL ADDITIONS section of help.txt
The first field on the first line of a help file should be a link to the
help file name. (See :h help-writing)
2019-04-29 13:32:31 +09:00
Junegunn Choi
1cd724dc23 Fix invalid detection of blockwise visual mode
Close #105
2017-06-03 22:10:13 +09:00
Junegunn Choi
14c693dfe5 Merge pull request #104 from D4D3VD4V3/patch-1
Fixed typo in docs
2017-06-01 01:15:46 +09:00
Dave
d3f8e64261 Fixed typo in docs 2017-05-31 21:18:52 +05:30
Junegunn Choi
3b395bd5ba Merge pull request #99 from yanma/default_nth
Add g:easy_align_nth to allow configuring default nth
2017-02-08 00:38:53 +09:00
Hiroaki Yamazoe
05cc60d222 add test case for g:easy_align_nth 2017-02-08 00:30:52 +09:00
Hiroaki Yamazoe
4be4101ad5 add g:easy_align_nth to allow configuring default nth 2017-02-04 19:57:39 +09:00
Junegunn Choi
3800a5405c Merge pull request #98 from jan-warchol/master
Fix typos in README.md
2017-01-28 11:09:55 +09:00
Jan Warchoł
2e27fe55ad Fix typos in README.md 2017-01-27 22:38:48 +01:00
Junegunn Choi
0cb6b98fc1 Use search pattern as delimiter if empty regex is given
Close #78
2016-03-06 13:47:17 +09:00
Junegunn Choi
dd98d0a895 Add " rule for vim comments
Related: #76
2016-02-05 11:06:00 +09:00
Junegunn Choi
d1b68f9dd0 Undo when LiveEasyAlign is cancelled via CTRL-C 2016-01-26 00:57:54 +09:00
Junegunn Choi
4fb4c1056c Clear command-line or restore visual selection on interrupt
Close #74
2016-01-26 00:52:09 +09:00
Junegunn Choi
7cb559eb70 Update EXAMPLES.md 2015-10-09 23:02:47 +09:00
Junegunn Choi
9ebd0e82da Remove DEMO.md 2015-10-09 22:27:43 +09:00
Junegunn Choi
9e6207246c Update README 2015-10-09 22:02:02 +09:00
Junegunn Choi
4732f10155 Update README 2015-10-09 18:42:19 +09:00
Junegunn Choi
cd124c2c0b Merge pull request #70 from junegunn/doc-update
Update README (#68)
2015-10-09 18:29:35 +09:00
Junegunn Choi
ed65b47f1b Update README (#68)
- Split the long demo into short gifs
- Clarify the modes of execution
2015-10-09 18:27:02 +09:00
Junegunn Choi
fac9f4dd75 Fix failing test case 2015-10-09 18:23:51 +09:00
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
14 changed files with 1003 additions and 763 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

91
DEMO.md
View File

@@ -1,91 +0,0 @@
# vim: set buftype=nofile colorcolumn= scrolloff=0 noshowcmd:
vim-easy-align
==============
Where's Lennon?
---------------
Paul McCartney 1942
George Harrison 1943
Ringo Starr 1940
Pete Best 1941
Formatting table
----------------
```
| 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 processing |
|batch | Boolean | false | enables batch processing mode |
|batch_size | Fixnum | nil | maximum number of items in batch|
|logger | Logger | nil | logger instance for debug logs |
```
Operators with = sign
---------------------
```ruby
a =
a = 1
bbbb = 2
ccccccc = 3
ccccccccccccccc
ddd = 4
eeee === eee = eee = eee=f
fff = ggg += gg &&= gg
g != hhhhhhhh == 888
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
```
Formatting YAML (or JSON)
-------------------------
```yaml
mysql:
# 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
```
Using blockwise-visual mode or negative N-th parameter
------------------------------------------------------
```ruby
options = { :caching => nil,
:versions => 3,
"cache=blocks" => false }.merge(options)
```
Commas
------
aaa, bb,c
d,eeeeeee
fffff, gggggggggg,
h, , ii
j,,k

View File

@@ -1,18 +1,23 @@
vim-easy-align examples
=======================
easy-align examples
===================
Open this document in your Vim and try it yourself.
This document assumes that you have defined the following mappings.
This document assumes that you have the following mappings in your .vimrc.
```vim
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <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)
```
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.
@@ -37,15 +42,17 @@ Alignment around whitespaces
You can align text around whitespaces with `<space>` delimiter key.
Try these commands:
Start the interactive mode as described above (`gaip` or `vipga`) and try
these commands:
- `<space>`
- `2<space>`
- `*<space>`
- `-<space>`
- `-2<space>`
- `<Enter><space>`
- `<Enter>2<space>`
- `<Enter>*<space>`
- `<Enter>-<space>`
- `<Enter>-2<space>`
- `<Enter><Enter><space>`
- `<Enter><Enter>*<space>`
- `<Enter><Enter><Enter>*<space>`
### Example
@@ -61,12 +68,13 @@ Pete Best 1941
Formatting table
----------------
Try these commands:
Again, start the interactive mode and try these commands:
- `*|`
- `**|`
- `<Enter>*|`
- `<Enter>**|`
- `<Enter><Enter>*|`
- `<Enter><Enter>**|`
- `<Enter><Enter><Enter>*|`
### Example
@@ -88,15 +96,16 @@ Try these commands:
Alignment around =
------------------
The default rule for delimiter key `=` aligns around a whole family of operators
containing `=` character.
The default rule for delimiter key `=` aligns around a whole family of
operators containing `=` character.
Try these commands:
- `<Enter>=`
- `<Enter>*=`
Try these commands in the interactive mode.
- `=`
- `*=`
- `**=`
- `<Enter>**=`
- `<Enter><Enter>**=`
- `<Enter><Enter><Enter>*=`
- `<Enter><Enter>*=`
### Example
@@ -132,8 +141,8 @@ gg <=> ee
Formatting YAML (or JSON)
-------------------------
Try `<Enter>:` here, to align text around only the first occurrences of colons.
In this case, you don't want to align around all the colons: `<Enter>*:`.
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:
@@ -148,7 +157,7 @@ mysql:
Formatting multi-line method chaining
-------------------------------------
Try `<Enter>.` or `<Enter>*.` on the following lines.
Try `.` or `*.` on the following lines.
```ruby
my_object
@@ -174,8 +183,8 @@ Using blockwise-visual mode or negative N-th parameter
------------------------------------------------------
You can try either:
- select text around `=>` in blockwise-visual mode (`CTRL-V`) and `<Enter>=`
- or `<Enter>-=`
- select text around `=>` in blockwise-visual mode (`CTRL-V`) and `ga=`
- or `gaip-=`
```ruby
options = { :caching => nil,
@@ -186,8 +195,7 @@ options = { :caching => nil,
Commas
------
There is also a predefined rule for commas, try `<Enter>*,` on the following
lines.
There is also a predefined rule for commas, try `*,`.
```
aaa, bb,c
@@ -201,7 +209,7 @@ Ignoring delimiters in comments or strings
------------------------------------------
Delimiters highlighted as comments or strings are ignored by default, try
`<Enter>*=` on the following lines.
`gaip*=` on the following lines.
```c
@@ -226,9 +234,9 @@ apple = 1 # comment not aligned
banana = 'Gros Michel' # comment 2
```
So, how do we align the trailing comments in the above lines?
Simply try `<Enter>-<space>`. The spaces in the comments are ignored, so the
trailing comment in each line is considered to be a single chunk.
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.
@@ -253,7 +261,7 @@ 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 `<Enter>#`, we get
Then on `#`, we get
```ruby
apple = 1 # comment not aligned
@@ -266,13 +274,16 @@ command:
```vim
" Using regular expression /#/
" - "is" is fuzzy-matched to "*i*gnore*s*"
:EasyAlign/#/{'is':['String']}
" - "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
highlighted as String is ignored.) If you don't want the second line to be
ignored, there are three options:
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
@@ -284,11 +295,13 @@ 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 fuzzy-matched to "*i*gnore_*u*nmatched"
" - "iu" is expanded to "*i*gnore_*u*nmatched"
:EasyAlign#{'iu':0}
" or
:EasyAlign#iu0
" 2-2. Using regular expression /#/
:EasyAlign/#/{'is':['String'],'iu':0}
:EasyAlign/#/ig['String']iu0
" 3. Update the alignment rule with ignore_unmatched option
let g:easy_align_delimiters['#'] = {
@@ -315,7 +328,7 @@ static double pi = 3.14;
```
We can align these lines with the predefined `=` rule. Select the lines and
press `<Enter>=`
press `ga=`
```c
const char* str = "Hello";
@@ -325,7 +338,7 @@ 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
`<Enter><space>` won't properly align those names.
`<space>`-rule won't properly align those names.
So let's define an alignment rule than can handle this case.
```vim
@@ -336,7 +349,7 @@ let g:easy_align_delimiters['d'] = {
```
This new rule aligns text around spaces that are *not* preceded by
`const` or `static`. Let's try it with `<Enter>d`.
`const` or `static`. Let's select the lines and try `gad`.
```c
const char* str = "Hello";
@@ -345,7 +358,7 @@ static double pi = 3.14;
```
Okay, the names are now aligned. We select the lines again with `gv`, and then
press `<Enter>=` to finish our alignment.
press `ga=` to finish our alignment.
```c
const char* str = "Hello";
@@ -376,14 +389,14 @@ So what do we do? Let's try to improve our alignment rule.
```vim
let g:easy_align_delimiters['d'] = {
\ 'pattern': ' \(\S\+\s*[;=]\)\@=',
\ '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 `<Enter>d`
Try `vipgad`
```c
const char* str = "Hello";
@@ -392,7 +405,7 @@ static double pi = 3.14;
static std::map<std::string, float>* scores = pointer;
```
We're right on track, now press `gv<Enter>=` and voila!
We're right on track, now press `gvga=` and voila!
```c
const char* str = "Hello";

424
README.md
View File

@@ -1,63 +1,35 @@
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.
Demo
----
![Screencast](https://raw.github.com/junegunn/i/master/vim-easy-align.gif)
(Too fast? Slower GIF is [here](https://raw.github.com/junegunn/i/master/vim-easy-align-slow.gif))
Features
--------
- 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
### _"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.
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/equals.gif)
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).
Use 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):
TL;DR - One-minute guide
------------------------
```vim
Plug 'junegunn/vim-easy-align'
```
Quick start guide
-----------------
Add the following mappings to your .vimrc.
```vim
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <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,
Then with the following lines of text,
```
apple =red
@@ -67,80 +39,110 @@ sky-= blue
try these commands:
- `vip<Enter>=`
- `vipga=`
- `v`isual-select `i`nner `p`aragraph
- Start EasyAlign command (`<Enter>`)
- Start EasyAlign command (`ga`)
- 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
[repeat.vim](https://github.com/tpope/vim-repeat). Install
[visualrepeat](https://github.com/vim-scripts/visualrepeat) as well if you want
to repeat in visual mode.
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 `,`.
#### `=`
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/equals.gif)
- `=` 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>`
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/spaces.gif)
- `<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
#### `,`
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/commas.gif)
- 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
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/regex.gif)
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
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/modes.gif)
This demo shows how you can start interactive mode with visual selection or use
non-interactive `:EasyAlign` command.
### Aligning table cells
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/tables.gif)
Check out various alignment options and "live interactive mode".
### Syntax-aware alignment
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/yaml.gif)
Delimiters in strings and comments are ignored by default.
### Using blockwise-visual mode
![](https://raw.githubusercontent.com/junegunn/i/master/easy-align/blockwise-visual.gif)
You can limit the scope with blockwise-visual mode.
Usage
-----
### Concept of _alignment rule_
### Flow of execution
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
<img src="https://raw.githubusercontent.com/junegunn/i/master/easy-align/usage.png" width="469">
There are two ways to use easy-align.
#### 1. Using `<Plug>` mappings
#### 1. `<Plug>` mappings (interactive mode)
The recommended method is to use `<Plug>` mappings as described earlier.
| 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
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]` |
### Interactive mode
The following sections will assume that you have `<Plug>(EasyAlign)` mappings in
your .vimrc as below:
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
" 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)
nmap ga <Plug>(EasyAlign)
xmap 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. `ga` 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)
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
- ...
@@ -149,58 +151,72 @@ With these mappings, you can align text with only 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>`
#### Predefined alignment rules
#### 2. Using `:EasyAlign` command
| 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 |
| `<Bar>` | Table markdown |
If you prefer command-line, use `:EasyAlign` command instead.
You can override these default rules or define your own rules with
`g:easy_align_delimiters`, which will be described in
[the later section](https://github.com/junegunn/vim-easy-align#extending-alignment-rules).
```vim
" Using predefined rules
:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
#### Examples
" Using regular expression
:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
```
| 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!**=` |
### Regular expression vs. predefined rules
#### Using regular expressions
You can use regular expressions but it's usually much easier to use predefined
alignment rules that you can trigger with a single keystroke.
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:
| 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 |
- `<Enter>`
- `*`
- `<CTRL-X>`
- `[0-9]\+`
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](https://github.com/junegunn/vim-easy-align#alignment-options).
[the following sections](#alignment-options).
| Key | Option | Values |
| --------- | ------------------ | -------------------------------------------------- |
@@ -210,30 +226,31 @@ keys listed below. The meaning of each option will be described in
| `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-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
#### 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)` 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.
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
### :EasyAlign command
Instead of starting interactive mode, you can use declarative, non-interactive
`:EasyAlign` command.
Instead of starting interactive mode, you can use non-interactive `:EasyAlign`
command.
```vim
" Using predefined alignment rules
@@ -252,8 +269,7 @@ Instead of starting interactive mode, you can use declarative, non-interactive
```
A command can end with alignment options, [each of which will be discussed in
detail later](https://github.com/junegunn/vim-easy-align#alignment-options),
in Vim dictionary format.
detail later](#alignment-options), in Vim dictionary format.
- `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': 0 }`
@@ -264,11 +280,11 @@ left. So we get:
apple;: banana:: cake
data;; exchange:; format
Option names are fuzzy-matched, so you can write as follows:
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, so concisely (or cryptically):
You can even omit spaces between the arguments.
- `:EasyAlign*/[:;]\+/{'s':1,'l':0}`
@@ -291,15 +307,6 @@ The following table summarizes the shorthand notation.
| `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>`
- `[:;]\+`
### Partial alignment in blockwise-visual mode
In blockwise-visual mode (`CTRL-V`), EasyAlign command aligns only the selected
@@ -399,7 +406,7 @@ 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.
" any of the following regular expressions, it will be ignored.
let g:easy_align_ignore_groups = ['Comment', 'String']
```
@@ -456,6 +463,19 @@ 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
`ignore_unmatched` option determines how EasyAlign command processes lines that
@@ -666,7 +686,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 +759,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,13 +31,14 @@ 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 },
\ '|': { 'pattern': '|', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
\ '.': { 'pattern': '\.', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 },
\ '#': { 'pattern': '#\+', 'delimiter_align': 'l', 'ignore_groups': ['!Comment'] },
\ '"': { 'pattern': '"\+', 'delimiter_align': 'l', 'ignore_groups': ['!Comment'] },
\ '&': { 'pattern': '\\\@<!&\|\\\\',
\ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
\ '{': { 'pattern': '(\@<!{',
@@ -88,9 +89,30 @@ function! s:floor2(v)
return a:v % 2 == 0 ? a:v : a:v - 1
endfunction
function! s:get_highlight_group_name(line, col)
let hl = synIDattr(synID(a:line, a:col, 0), 'name')
if hl == '' && has('nvim-0.9.0')
let insp = luaeval('vim.inspect_pos and vim.inspect_pos( nil, ' .. (a:line-1) .. ', ' .. (a:col-1) .. ' ) or { treesitter = {} }')
if !empty(insp.treesitter)
let hl = insp.treesitter[0].hl_group_link
endif
endif
" and, finally
return hl
endfunction
function! easy_align#get_highlight_group_name(...)
let l = get(a:, 1, line('.'))
let c = get(a:, 2, col('.'))
let hl = s:get_highlight_group_name(l, c)
return { 'line': l, 'column': c, 'group': hl }
endfunction
function! s:highlighted_as(line, col, groups)
if empty(a:groups) | return 0 | endif
let hl = synIDattr(synID(a:line, a:col, 0), 'name')
let hl = s:get_highlight_group_name(a:line, a:col)
for grp in a:groups
if grp[0] == '!'
if hl !~# grp[1:-1]
@@ -146,7 +168,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', ' ']]
@@ -264,11 +286,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 = []
@@ -277,18 +296,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)
@@ -358,9 +381,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
@@ -617,7 +641,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
@@ -636,11 +660,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
@@ -655,7 +679,11 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
let check = 0
let warn = ''
let c = getchar()
try
let c = getchar()
catch /^Vim:Interrupt$/
let c = 27
endtry
let ch = nr2char(c)
if c == 3 || c == 27 " CTRL-C / ESC
if undo
@@ -672,7 +700,7 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
elseif c == 13 " Enter key
let mode = s:shift(a:modes, 1)
if has_key(opts, 'a')
let opts.m = mode . strpart(opts.m, 1)
let opts.a = mode . strpart(opts.a, 1)
endif
elseif ch == '-'
if empty(n) | let n = '-'
@@ -713,6 +741,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
@@ -737,7 +776,7 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live)
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
@@ -746,7 +785,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
@@ -770,7 +809,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
@@ -789,9 +831,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
@@ -806,10 +850,11 @@ function! s:valid_regexp(regexp)
endfunction
function! s:test_regexp(regexp)
if !s:valid_regexp(a:regexp)
call s:exit('Invalid regular expression: '. a:regexp)
let regexp = empty(a:regexp) ? @/ : a:regexp
if !s:valid_regexp(regexp)
call s:exit('Invalid regular expression: '. regexp)
endif
return a:regexp
return regexp
endfunction
let s:shorthand_regex =
@@ -829,7 +874,6 @@ 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', 'a']
if stridx(tolower(m), key) == 0
@@ -960,9 +1004,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)
@@ -1027,22 +1071,21 @@ function! s:build_mode_sequence(expr, recur)
endfunction
function! s:process(range, mode, n, ch, opts, regexp, rules, bvis)
let [nth, recur] = s:parse_nth(a:n)
let [nth, recur] = s:parse_nth((empty(a:n) && exists('g:easy_align_nth')) ? g:easy_align_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, '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
@@ -1066,10 +1109,12 @@ endfunction
function! s:align(bang, live, visualmode, first_line, last_line, expr)
" Heuristically determine if the user was in visual mode
if empty(a:visualmode)
if a:visualmode == 'command'
let vis = a:first_line == line("'<") && a:last_line == line("'>")
let bvis = vis && visualmode() == "\<C-V>"
" Visual-mode explicitly given
elseif empty(a:visualmode)
let vis = 0
let bvis = 0
else
let vis = 1
let bvis = a:visualmode == "\<C-V>"
@@ -1077,10 +1122,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')
@@ -1094,11 +1136,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)
@@ -1112,10 +1154,17 @@ endfunction
function! easy_align#align(bang, live, visualmode, expr) range
try
call s:align(a:bang, a:live, a:visualmode, a:firstline, a:lastline, a:expr)
catch 'exit'
catch /^\%(Vim:Interrupt\|exit\)$/
if empty(a:visualmode)
echon "\r"
echon "\r"
else
normal! gv
endif
endtry
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: set et sw=2 :

View File

@@ -1,51 +1,43 @@
easy-align.txt vim-easy-align Last change: August 14 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}.
Use 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,7 +137,7 @@ 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> ,
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
@@ -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,66 +200,72 @@ 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 `\\` )
`#` | Ruby/Python comments
`=` | 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
(|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:<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!**=
------------------+------------------------------------+--------------------
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~
@@ -281,36 +273,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-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 }`
--------+--------------------+---------------------------------------------------
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 >_____________________________________________________~
@@ -321,15 +317,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 >______________________________________________________~
@@ -353,14 +348,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
@@ -373,24 +368,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*/[:;]\+/<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]`
-------------------+-----------
`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:
@@ -399,7 +396,9 @@ follows:
- `*`
- <Left>
- CTRL-X
- `[:;]\+`
- `[:;]\+`
{6} https://github.com/junegunn/vim-easy-align#alignment-options
< Partial alignment in blockwise-visual mode >________________________________~
@@ -409,7 +408,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,
@@ -417,8 +417,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,
@@ -437,19 +437,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
`align` | string | `l` | 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):
@@ -461,17 +463,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> | `<` 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*]*` |
-------------------+-----------------+-------------+--------------------------------
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 >___________________________________________________________~
@@ -482,14 +486,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/
@@ -512,7 +517,7 @@ 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.
" any of the following regular expressions, it will be ignored.
let g:easy_align_ignore_groups = ['Comment', 'String']
<
For example, the following paragraph
@@ -562,13 +567,24 @@ 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()
" Highlight group name of the line 10, column 20
echo easy_align#get_highlight_group_name(10, 20)
<
< 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
@@ -623,8 +639,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
@@ -704,8 +720,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:
>
@@ -727,9 +743,9 @@ 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 'align' option. (The option can also be set in interactive
mode with the special key CTRL-A)
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' }
@@ -767,13 +783,13 @@ mode with the special key CTRL-A)
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 = {
@@ -813,16 +829,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*
@@ -834,15 +850,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']
@@ -852,115 +867,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
"
@@ -26,8 +26,8 @@ if exists("g:loaded_easy_align_plugin")
endif
let g:loaded_easy_align_plugin = 1
command! -nargs=* -range -bang EasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 0, '', <q-args>)
command! -nargs=* -range -bang LiveEasyAlign <line1>,<line2>call easy_align#align('<bang>' == '!', 1, '', <q-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'
@@ -75,6 +75,12 @@ 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"
@@ -93,7 +99,7 @@ function! s:generic_easy_align_op(type, vmode, live)
if get(g:, 'easy_align_need_repeat', 0)
execute range . g:easy_align_last_command
else
execute range . "call easy_align#align('<bang>' == '!', a:live, vmode, '')"
execute range . "call easy_align#align(0, a:live, vmode, '')"
end
call s:set_repeat()
finally
@@ -134,3 +140,4 @@ vnoremap <silent> <Plug>(EasyAlignRepeat) :<C-U>call <SID>repeat_in_visual()<Ent
" Backward-compatibility (deprecated)
nnoremap <silent> <Plug>(EasyAlignOperator) :set opfunc=<SID>easy_align_op<Enter>g@
" vim: set et sw=2 :

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

@@ -105,6 +105,14 @@ 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:

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

@@ -161,4 +161,103 @@ Expect:
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

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>
|
@@ -520,6 +581,120 @@ Do:
Execute (g:easy_align_last_command should not be set if interrupted):
Assert !exists('g:easy_align_last_command')
Do (g:easy_align_nth is not set (work with default value 1)):
vip\<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 |
Execute (set g:easy_align_nth):
let g:easy_align_nth = '2'
Do (g:easy_align_nth is set as 2):
vip\<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 |
Execute (unset g:easy_align_nth):
unlet g:easy_align_nth
Execute (set g:easy_align_nth):
let g:easy_align_nth = '*'
Do (g:easy_align_nth is set as *):
vip\<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 |
Execute (unset g:easy_align_nth):
unlet g:easy_align_nth
Execute (set g:easy_align_nth):
let g:easy_align_nth = '**'
Do (g:easy_align_nth is set as **):
vip\<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 |
Execute (unset g:easy_align_nth):
unlet g:easy_align_nth
Execute (set g:easy_align_nth):
let g:easy_align_nth = '-'
Do (g:easy_align_nth is set as -):
vip\<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 |
Execute (unset g:easy_align_nth):
unlet g:easy_align_nth
Execute (set g:easy_align_nth):
let g:easy_align_nth = '-2'
Do (g:easy_align_nth is set as -2):
vip\<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 |
Execute (unset g:easy_align_nth):
unlet g:easy_align_nth
###########################################################
Given (comma-separated items):
@@ -1474,6 +1649,67 @@ 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):
:set ve=block\<Enter>
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"}}}
Then:
set ve=
###########################################################
Given (hard-tab indentation (#19)):
@@ -1627,7 +1863,7 @@ Do (Blockwise-visual-operator is also repeatable):
f1
4j
\<Enter>:
7G
7G0
fa
.