mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-09 18:33:49 -05:00
Add CTRL-O special key for mode_sequence option
This commit is contained in:
@@ -227,6 +227,7 @@ keys listed below.
|
|||||||
| `CTRL-D` | `delimiter_align` | left, center, right |
|
| `CTRL-D` | `delimiter_align` | left, center, right |
|
||||||
| `CTRL-U` | `ignore_unmatched` | 0, 1 |
|
| `CTRL-U` | `ignore_unmatched` | 0, 1 |
|
||||||
| `CTRL-G` | `ignore_groups` | [], ['String'], ['Comment'], ['String', 'Comment'] |
|
| `CTRL-G` | `ignore_groups` | [], ['String'], ['Comment'], ['String', 'Comment'] |
|
||||||
|
| `CTRL-O` | `mode_sequence` | Input string of l, r, and c characters |
|
||||||
|
|
||||||
### Ignoring delimiters in comments or strings
|
### Ignoring delimiters in comments or strings
|
||||||
|
|
||||||
@@ -477,7 +478,8 @@ To recap:
|
|||||||
```
|
```
|
||||||
|
|
||||||
In addition to these, you can fine-tune alignments over multiple occurrences of
|
In addition to these, you can fine-tune alignments over multiple occurrences of
|
||||||
the delimiters with 'mode_sequence' option.
|
the delimiters with 'mode_sequence' option. (The option can also be given
|
||||||
|
in interactive mode with the special key `CTRL-O`.)
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Left alignment over the first two occurrences of delimiters
|
" Left alignment over the first two occurrences of delimiters
|
||||||
|
|||||||
@@ -503,6 +503,9 @@ function! s:interactive(modes)
|
|||||||
endif
|
endif
|
||||||
elseif c == 13 " Enter key
|
elseif c == 13 " Enter key
|
||||||
let mode = s:shift(a:modes, 1)
|
let mode = s:shift(a:modes, 1)
|
||||||
|
if has_key(opts, 'm')
|
||||||
|
let opts.m = mode . strpart(opts.m, 1)
|
||||||
|
endif
|
||||||
elseif ch == '-'
|
elseif ch == '-'
|
||||||
if empty(n) | let n = '-'
|
if empty(n) | let n = '-'
|
||||||
elseif n == '-' | let n = ''
|
elseif n == '-' | let n = ''
|
||||||
@@ -530,11 +533,21 @@ function! s:interactive(modes)
|
|||||||
let opts['iu'] = s:shift(vals['ignore_unmatched'], 1)
|
let opts['iu'] = s:shift(vals['ignore_unmatched'], 1)
|
||||||
elseif ch == "\<C-G>"
|
elseif ch == "\<C-G>"
|
||||||
let opts['ig'] = s:shift(vals['ignore_groups'], 1)
|
let opts['ig'] = s:shift(vals['ignore_groups'], 1)
|
||||||
|
elseif ch == "\<C-O>"
|
||||||
|
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode)))
|
||||||
|
if match(modes, '^[lrc]\+$') != -1
|
||||||
|
let opts['m'] = modes
|
||||||
|
let mode = modes[0]
|
||||||
|
while mode != s:shift(a:modes, 1)
|
||||||
|
endwhile
|
||||||
|
else
|
||||||
|
silent! call remove(opts, 'm')
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
return [mode, n, ch, s:normalize_options(opts)]
|
return [mode, n, ch, opts, s:normalize_options(opts)]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_args(args)
|
function! s:parse_args(args)
|
||||||
@@ -602,16 +615,17 @@ function! easy_align#align(bang, expr) range
|
|||||||
let n = ''
|
let n = ''
|
||||||
let ch = ''
|
let ch = ''
|
||||||
let opts = {}
|
let opts = {}
|
||||||
|
let ioptsr = {}
|
||||||
let iopts = {}
|
let iopts = {}
|
||||||
let regexp = 0
|
let regexp = 0
|
||||||
|
|
||||||
try
|
try
|
||||||
if empty(a:expr)
|
if empty(a:expr)
|
||||||
let [mode, n, ch, iopts] = s:interactive(copy(modes))
|
let [mode, n, ch, ioptsr, iopts] = 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, iopts] = s:interactive(copy(modes))
|
let [mode, n, ch, ioptsr, iopts] = 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]
|
||||||
@@ -694,7 +708,7 @@ function! easy_align#align(bang, expr) range
|
|||||||
\ get(dict, 'ignore_unmatched', get(g:, 'easy_align_ignore_unmatched', 1)),
|
\ get(dict, 'ignore_unmatched', get(g:, 'easy_align_ignore_unmatched', 1)),
|
||||||
\ get(dict, 'ignore_groups', get(dict, 'ignores', s:ignored_syntax())),
|
\ get(dict, 'ignore_groups', get(dict, 'ignores', s:ignored_syntax())),
|
||||||
\ recur)
|
\ recur)
|
||||||
call s:echon(mode, n, regexp ? '/'.ch.'/' : ch, iopts)
|
call s:echon(mode, n, regexp ? '/'.ch.'/' : ch, ioptsr)
|
||||||
catch 'exit'
|
catch 'exit'
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user