Implement filter option (#16, #17)

This commit implements filter option which can be used to filter lines within
the range based on the given pattern. The value of filter option should be
either `g/pattern/` or `v/pattern/`. The former aligns lines that match the
pattern, the latter aligns lines that do not match the pattern.
This commit is contained in:
Junegunn Choi
2013-10-27 03:10:04 +09:00
parent 1a232ac19b
commit 2832a76cea
4 changed files with 182 additions and 7 deletions

View File

@@ -201,6 +201,7 @@ The following table summarizes the shorthand notation.
| Option | Expression |
| -------------- | ---------- |
| filter | [gv]/.*/ |
| left_margin | l[0-9]+ |
| right_margin | r[0-9]+ |
| stick_to_left | s[01] |
@@ -234,6 +235,7 @@ Available options are as follows.
| Atrribute | Type | Default |
| ---------------- | ---------------- | ----------------------------- |
| filter | string | |
| left_margin | number or string | 1 |
| right_margin | number or string | 1 |
| stick_to_left | boolean | 0 |
@@ -255,6 +257,7 @@ There are 4 ways to set alignment options (from lowest precedence to highest):
| Option | Shortcut key | Abbreviated | Global variable |
| ---------------- | --------------- | ----------- | ----------------------------- |
| filter | CTRL-F | [gv]/.*/ | |
| left_margin | CTRL-L | l[0-9]+ | |
| right_margin | CTRL-R | r[0-9]+ | |
| stick_to_left | <Left>, <Right> | s[01] | |
@@ -265,6 +268,30 @@ There are 4 ways to set alignment options (from lowest precedence to highest):
| mode_sequence | CTRL-O | m[lrc*]+ | |
Filtering lines
-------------------------------------------------------------------------
With filter option, you can align lines that only match or do not match a
given pattern. There are several ways to set the pattern.
1. Press CTRL-F in interactive mode and input g/pat/ or v/pat/
2. In command-line, it can be written in dictionary format: {'filter': 'g/pat/'}
3. Or in shorthand notation: g/pat/ or v/pat/
Examples:
" Start interactive mode with filter option set to g/hello/
EasyAlign g/hello/
" Start live interactive mode with filter option set to v/goodbye/
LiveEasyAlign v/goodbye/
" Align the lines with 'hi' around the first colons
EasyAlign : g/hi/
(You don't need to escape '/'s in the regular expression)
Ignoring delimiters in comments or strings *g:easy_align_ignore_groups*
-------------------------------------------------------------------------