mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-13 04:13:48 -05:00
Implement shortcut expression for options
This commit is contained in:
27
README.md
27
README.md
@@ -172,7 +172,7 @@ Go try out vim-easy-align right now, and come back later when you feel like it.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Non-interactive mode
|
### Non-interactive mode (command line)
|
||||||
|
|
||||||
Instead of going into the interactive mode, you can type in arguments to
|
Instead of going into the interactive mode, you can type in arguments to
|
||||||
`:EasyAlign` command.
|
`:EasyAlign` command.
|
||||||
@@ -225,6 +225,31 @@ key combination.
|
|||||||
- `<CTRL-/>` (or `<CTRL-X>` on GVim)
|
- `<CTRL-/>` (or `<CTRL-X>` on GVim)
|
||||||
- `[:;]\+`
|
- `[:;]\+`
|
||||||
|
|
||||||
|
#### Options in shortcut expression
|
||||||
|
|
||||||
|
When you use regular expression in command line, options dictionary can be
|
||||||
|
written concisely using shortcut expression.
|
||||||
|
|
||||||
|
For example, the command we saw in the previous section,
|
||||||
|
|
||||||
|
- `:EasyAlign*/[:;]\+/{'s':1,'l':0}`
|
||||||
|
|
||||||
|
can also be written as
|
||||||
|
|
||||||
|
- `:EasyAlign*/[:;]\+/s1l0`
|
||||||
|
|
||||||
|
Supported shortcut expressions are listed below.
|
||||||
|
|
||||||
|
| Expression | Option |
|
||||||
|
| ---------- | ---------------- |
|
||||||
|
| `l[0-9]` | left_margin |
|
||||||
|
| `r[0-9]` | right_margin |
|
||||||
|
| `s[01]` | stick_to_left |
|
||||||
|
| `u[01]` | ignore_unmatched |
|
||||||
|
| `d[lrc]` | delimiter_align |
|
||||||
|
| `m[lrc*]*` | mode_sequence |
|
||||||
|
| `i[ksdn]` | indentation |
|
||||||
|
|
||||||
### Partial alignment in blockwise-visual mode
|
### Partial alignment in blockwise-visual mode
|
||||||
|
|
||||||
In blockwise-visual mode (`CTRL-V`), EasyAlign command aligns only the selected
|
In blockwise-visual mode (`CTRL-V`), EasyAlign command aligns only the selected
|
||||||
|
|||||||
@@ -688,6 +688,39 @@ function! s:test_regexp(regexp)
|
|||||||
return a:regexp
|
return a:regexp
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:parse_shortcut_opts(expr)
|
||||||
|
let opts = {}
|
||||||
|
let expr = tolower(substitute(a:expr, '\s', '', 'g'))
|
||||||
|
let regex =
|
||||||
|
\ '^\('
|
||||||
|
\ .'\(l[0-9]\+\)\|\(r[0-9]\+\)\|\(u[01]\)\|\(s[01]\)\|'
|
||||||
|
\ .'\(d[clr]\)\|\(m[lrc*]\+\)\|\(i[kdsn]\)'
|
||||||
|
\ .'\)\+$'
|
||||||
|
|
||||||
|
if empty(expr)
|
||||||
|
return opts
|
||||||
|
elseif expr !~ regex
|
||||||
|
call s:exit("Invalid expression: ". a:expr)
|
||||||
|
else
|
||||||
|
let match = matchlist(expr, regex)
|
||||||
|
if empty(match) | break | endif
|
||||||
|
for m in filter(match[ 2 : -1 ], '!empty(v:val)')
|
||||||
|
let k = m[0]
|
||||||
|
let rest = m[1 : -1]
|
||||||
|
if index(['l', 'r', 's'], k) >= 0
|
||||||
|
let opts[k] = str2nr(rest)
|
||||||
|
elseif k == 'u'
|
||||||
|
let opts['iu'] = str2nr(rest)
|
||||||
|
elseif k == 'i'
|
||||||
|
let opts['idt'] = rest
|
||||||
|
else
|
||||||
|
let opts[k] = rest
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
return s:normalize_options(opts)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:parse_args(args)
|
function! s:parse_args(args)
|
||||||
let n = ''
|
let n = ''
|
||||||
let ch = ''
|
let ch = ''
|
||||||
@@ -728,10 +761,13 @@ function! s:parse_args(args)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Has /Regexp/?
|
" Has /Regexp/?
|
||||||
let matches = matchlist(args, '^\(.\{-}\)\s*/\(.*\)/\s*$')
|
let matches = matchlist(args, '^\(.\{-}\)\s*/\(.*\)/\(.\{-}\)$')
|
||||||
|
|
||||||
" Found regexp
|
" Found regexp
|
||||||
if !empty(matches)
|
if !empty(matches)
|
||||||
|
if empty(opts) && !empty(matches[3])
|
||||||
|
let opts = s:parse_shortcut_opts(matches[3])
|
||||||
|
endif
|
||||||
return [matches[1], s:test_regexp(matches[2]), opts, 1]
|
return [matches[1], s:test_regexp(matches[2]), opts, 1]
|
||||||
else
|
else
|
||||||
let tokens = matchlist(args, '^\([1-9][0-9]*\|-[0-9]*\|\*\*\?\)\?\s*\(.\{-}\)\?$')
|
let tokens = matchlist(args, '^\([1-9][0-9]*\|-[0-9]*\|\*\*\?\)\?\s*\(.\{-}\)\?$')
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ described in the following sections.
|
|||||||
| <Down> | *_margin | { 'left_margin': 0, 'right_margin': 0 } |
|
| <Down> | *_margin | { 'left_margin': 0, 'right_margin': 0 } |
|
||||||
|
|
||||||
|
|
||||||
Non-interactive mode
|
Non-interactive mode (command line)
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
Instead of going into the interactive mode, you can type in arguments to
|
Instead of going into the interactive mode, you can type in arguments to
|
||||||
@@ -152,6 +152,29 @@ key combination.
|
|||||||
- <CTRL-/> (or <CTRL-X> on GVim)
|
- <CTRL-/> (or <CTRL-X> on GVim)
|
||||||
- [:;]\+
|
- [:;]\+
|
||||||
|
|
||||||
|
When you use regular expression in command line, options dictionary can be
|
||||||
|
written concisely using shortcut expression.
|
||||||
|
|
||||||
|
For example, the command we saw in the previous section,
|
||||||
|
|
||||||
|
- :EasyAlign*/[:;]\+/{'s':1,'l':0}
|
||||||
|
|
||||||
|
can also be written as
|
||||||
|
|
||||||
|
- :EasyAlign*/[:;]\+/s1l0
|
||||||
|
|
||||||
|
Supported shortcut expressions are listed below.
|
||||||
|
|
||||||
|
| Expression | Option |
|
||||||
|
| ---------- | -------------- |
|
||||||
|
| l[0-9] | left_margin |
|
||||||
|
| r[0-9] | right_margin |
|
||||||
|
| s[01] | stick_to_left |
|
||||||
|
| u[01] | ignore_unmatched |
|
||||||
|
| d[lrc] | delimiter_align |
|
||||||
|
| m[lrc*]* | mode_sequence |
|
||||||
|
| i[ksdn] | indentation |
|
||||||
|
|
||||||
|
|
||||||
Partial alignment in blockwise-visual mode
|
Partial alignment in blockwise-visual mode
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -94,3 +94,15 @@ banana = 'Gros Michel' # comment 2
|
|||||||
a()p()p()l()e();():()b()a()n()a()n()a():():()c()a()k()e(
|
a()p()p()l()e();():()b()a()n()a()n()a():():()c()a()k()e(
|
||||||
d()a()t()a();();()e()x()c()h()a()n()g()e():();()f()o()r()m()a()t(
|
d()a()t()a();();()e()x()c()h()a()n()g()e():();()f()o()r()m()a()t(
|
||||||
|
|
||||||
|
apple ;: banana :: cake
|
||||||
|
data ;;exchange :;format
|
||||||
|
|
||||||
|
apple ;: banana :: cake
|
||||||
|
data ;; exchange :; format
|
||||||
|
|
||||||
|
apple;:banana ::cake
|
||||||
|
data ;;exchange:;format
|
||||||
|
|
||||||
|
apple ;: banana :: cake
|
||||||
|
data ;; exchange :; format
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
4Gvipjyvip:EasyAlign:
|
4Gvipjyvip:EasyAlign:
|
||||||
|
|||||||
Reference in New Issue
Block a user