mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-13 04:13:48 -05:00
Regular expression in interactive mode (#8)
This commit is contained in:
14
README.md
14
README.md
@@ -117,6 +117,17 @@ You can override these default rules or define your own rules with
|
|||||||
| `<Enter><Enter>**=` | Right-left alternating alignment around all equals signs | `:'<,'>EasyAlign!**=` |
|
| `<Enter><Enter>**=` | Right-left alternating alignment around all equals signs | `:'<,'>EasyAlign!**=` |
|
||||||
| ... | ... | |
|
| ... | ... | |
|
||||||
|
|
||||||
|
#### Using regular expressions
|
||||||
|
|
||||||
|
Instead of finishing the command with a predefined delimiter key, you can type
|
||||||
|
in a regular expression after `<CTRL-/>` key. For example, if you want to align
|
||||||
|
text around all occurrences of numbers:
|
||||||
|
|
||||||
|
- `<Enter>`
|
||||||
|
- `*`
|
||||||
|
- `<CTRL-/>`
|
||||||
|
- `[0-9]\+`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### *Intermission*
|
### *Intermission*
|
||||||
@@ -132,8 +143,7 @@ Go try out vim-easy-align right now, and come back later when you feel like it.
|
|||||||
### Non-interactive mode
|
### Non-interactive mode
|
||||||
|
|
||||||
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. In non-interactive mode, you can even use arbitrary
|
`:EasyAlign` command.
|
||||||
regular expressions.
|
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Using predefined alignment rules
|
" Using predefined alignment rules
|
||||||
|
|||||||
@@ -498,6 +498,7 @@ function! s:interactive(modes)
|
|||||||
let ch = ''
|
let ch = ''
|
||||||
let opts = {}
|
let opts = {}
|
||||||
let vals = deepcopy(s:option_values)
|
let vals = deepcopy(s:option_values)
|
||||||
|
let regx = 0
|
||||||
|
|
||||||
while 1
|
while 1
|
||||||
call s:echon(mode, n, '', opts)
|
call s:echon(mode, n, '', opts)
|
||||||
@@ -552,11 +553,17 @@ function! s:interactive(modes)
|
|||||||
else
|
else
|
||||||
silent! call remove(opts, 'm')
|
silent! call remove(opts, 'm')
|
||||||
endif
|
endif
|
||||||
|
elseif ch == "\<C-_>"
|
||||||
|
let ch = s:input('Regular expression: ', '')
|
||||||
|
if !empty(ch)
|
||||||
|
let regx = 1
|
||||||
|
break
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
return [mode, n, ch, opts, s:normalize_options(opts)]
|
return [mode, n, ch, opts, s:normalize_options(opts), regx]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_args(args)
|
function! s:parse_args(args)
|
||||||
@@ -630,11 +637,11 @@ function! easy_align#align(bang, expr) range
|
|||||||
|
|
||||||
try
|
try
|
||||||
if empty(a:expr)
|
if empty(a:expr)
|
||||||
let [mode, n, ch, ioptsr, iopts] = s:interactive(copy(modes))
|
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes))
|
||||||
else
|
else
|
||||||
let [n, ch, opts, regexp] = s:parse_args(a:expr)
|
let [n, ch, opts, regexp] = s:parse_args(a:expr)
|
||||||
if empty(n) && empty(ch)
|
if empty(n) && empty(ch)
|
||||||
let [mode, n, ch, ioptsr, iopts] = s:interactive(copy(modes))
|
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes))
|
||||||
elseif empty(ch)
|
elseif empty(ch)
|
||||||
" Try swapping n and ch
|
" Try swapping n and ch
|
||||||
let [n, ch] = ['', n]
|
let [n, ch] = ['', n]
|
||||||
|
|||||||
Reference in New Issue
Block a user