From 301bdbcfc70f3a0ba9c4015ac19a4b6293e056ae Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 14 Sep 2013 00:40:16 +0900 Subject: [PATCH] Regular expression in interactive mode (#8) --- README.md | 14 ++++++++++++-- autoload/easy_align.vim | 13 ++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a103b6e..b0c284b 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,17 @@ You can override these default rules or define your own rules with | `**=` | 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 `` key. For example, if you want to align +text around all occurrences of numbers: + +- `` +- `*` +- `` + - `[0-9]\+` + --- ### *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 Instead of going into the interactive mode, you can type in arguments to -`:EasyAlign` command. In non-interactive mode, you can even use arbitrary -regular expressions. +`:EasyAlign` command. ```vim " Using predefined alignment rules diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index e1f2961..0b1fe3b 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -498,6 +498,7 @@ function! s:interactive(modes) let ch = '' let opts = {} let vals = deepcopy(s:option_values) + let regx = 0 while 1 call s:echon(mode, n, '', opts) @@ -552,11 +553,17 @@ function! s:interactive(modes) else silent! call remove(opts, 'm') endif + elseif ch == "\" + let ch = s:input('Regular expression: ', '') + if !empty(ch) + let regx = 1 + break + endif else break endif endwhile - return [mode, n, ch, opts, s:normalize_options(opts)] + return [mode, n, ch, opts, s:normalize_options(opts), regx] endfunction function! s:parse_args(args) @@ -630,11 +637,11 @@ function! easy_align#align(bang, expr) range try 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 let [n, ch, opts, regexp] = s:parse_args(a:expr) 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) " Try swapping n and ch let [n, ch] = ['', n]