mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-11 11:23:49 -05:00
- <Left> and <Right> key to toggle stick_to_left option - <CTRL-X> in addition to <CTRL-/> to take regular expression - Retain visual selection display on <CTRL-O/L/R/X>
This commit is contained in:
39
README.md
39
README.md
@@ -120,14 +120,34 @@ You can override these default rules or define your own rules with
|
||||
#### 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:
|
||||
in a regular expression after `<CTRL-/>` or `<CTRL-X>` key.
|
||||
For example, if you want to align text around all occurrences of numbers:
|
||||
|
||||
- `<Enter>`
|
||||
- `*`
|
||||
- `<CTRL-/>`
|
||||
- `<CTRL-/>` or `<CTRL-X>`
|
||||
- `[0-9]\+`
|
||||
|
||||
(`<CTRL-/>` key will not work in GVim, then you have to use `<CTRL-X>` instead)
|
||||
|
||||
#### Alignment options in interactive mode
|
||||
|
||||
While in interactive mode, you can switch some of the alignment options using
|
||||
special shortcut keys listed below. The meanings of the options will be
|
||||
described in the following sections.
|
||||
|
||||
| Key | Option | Values |
|
||||
| -------- | ------------------ | -------------------------------------------------- |
|
||||
| `CTRL-I` | `indentation` | shallow, deep, none, keep |
|
||||
| `CTRL-L` | `left_margin` | Input number or string |
|
||||
| `CTRL-R` | `right_margin` | Input number or string |
|
||||
| `CTRL-D` | `delimiter_align` | left, center, right |
|
||||
| `CTRL-U` | `ignore_unmatched` | 0, 1 |
|
||||
| `CTRL-G` | `ignore_groups` | [], ['String'], ['Comment'], ['String', 'Comment'] |
|
||||
| `CTRL-O` | `mode_sequence` | Input string of `/[lrc]+\*{0,2}/` |
|
||||
| `<Left>` | `stick_to_left` | Set stick_to_left option |
|
||||
| `<Right>` | `stick_to_left` | Unset stick_to_left option |
|
||||
|
||||
---
|
||||
|
||||
### *Intermission*
|
||||
@@ -246,19 +266,6 @@ Some of the options can be specified using corresponding global variables.
|
||||
| `delimiter_align` | `g:easy_align_delimiter_align` |
|
||||
| `indentation` | `g:easy_align_indentation` |
|
||||
|
||||
In interactive mode, you can switch some of the alignment options using special
|
||||
keys listed below.
|
||||
|
||||
| Key | Option | Values |
|
||||
| -------- | ------------------ | -------------------------------------------------- |
|
||||
| `CTRL-I` | `indentation` | shallow, deep, none, keep |
|
||||
| `CTRL-L` | `left_margin` | Input number or string |
|
||||
| `CTRL-R` | `right_margin` | Input number or string |
|
||||
| `CTRL-D` | `delimiter_align` | left, center, right |
|
||||
| `CTRL-U` | `ignore_unmatched` | 0, 1 |
|
||||
| `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
|
||||
|
||||
EasyAlign can be configured to ignore delimiters in certain syntax highlight
|
||||
|
||||
@@ -480,8 +480,15 @@ function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:input(str, default)
|
||||
redraw
|
||||
function! s:input(str, default, sl)
|
||||
if !a:sl
|
||||
normal! gv
|
||||
redraw
|
||||
execute "normal! \<esc>"
|
||||
else
|
||||
" EasyAlign command can be called without visual selection
|
||||
redraw
|
||||
endif
|
||||
call inputsave()
|
||||
let got = input(a:str, a:default)
|
||||
call inputrestore()
|
||||
@@ -492,7 +499,7 @@ function! s:input(str, default)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:interactive(modes)
|
||||
function! s:interactive(modes, sl)
|
||||
let mode = s:shift(a:modes, 1)
|
||||
let n = ''
|
||||
let ch = ''
|
||||
@@ -536,15 +543,19 @@ function! s:interactive(modes)
|
||||
elseif ch == "\<C-I>"
|
||||
let opts['idt'] = s:shift(vals['indentation'], 1)
|
||||
elseif ch == "\<C-L>"
|
||||
let opts['lm'] = s:input("Left margin: ", get(opts, 'lm', ''))
|
||||
let opts['lm'] = s:input("Left margin: ", get(opts, 'lm', ''), a:sl)
|
||||
elseif ch == "\<C-R>"
|
||||
let opts['rm'] = s:input("Right margin: ", get(opts, 'rm', ''))
|
||||
let opts['rm'] = s:input("Right margin: ", get(opts, 'rm', ''), a:sl)
|
||||
elseif ch == "\<C-U>"
|
||||
let opts['iu'] = s:shift(vals['ignore_unmatched'], 1)
|
||||
elseif ch == "\<C-G>"
|
||||
let opts['ig'] = s:shift(vals['ignore_groups'], 1)
|
||||
elseif c == "\<Left>"
|
||||
let opts['stl'] = 1
|
||||
elseif c == "\<Right>"
|
||||
let opts['stl'] = 0
|
||||
elseif ch == "\<C-O>"
|
||||
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode)))
|
||||
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode), a:sl))
|
||||
if match(modes, '^[lrc]\+\*\{0,2}$') != -1
|
||||
let opts['m'] = modes
|
||||
let mode = modes[0]
|
||||
@@ -553,8 +564,8 @@ function! s:interactive(modes)
|
||||
else
|
||||
silent! call remove(opts, 'm')
|
||||
endif
|
||||
elseif ch == "\<C-_>"
|
||||
let ch = s:input('Regular expression: ', '')
|
||||
elseif ch == "\<C-_>" || ch == "\<C-X>"
|
||||
let ch = s:input('Regular expression: ', '', a:sl)
|
||||
if !empty(ch)
|
||||
let regx = 1
|
||||
break
|
||||
@@ -634,14 +645,15 @@ function! easy_align#align(bang, expr) range
|
||||
let ioptsr = {}
|
||||
let iopts = {}
|
||||
let regexp = 0
|
||||
let sl = a:firstline == a:lastline " Possibley w/o selection
|
||||
|
||||
try
|
||||
if empty(a:expr)
|
||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes))
|
||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), sl)
|
||||
else
|
||||
let [n, ch, opts, regexp] = s:parse_args(a:expr)
|
||||
if empty(n) && empty(ch)
|
||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes))
|
||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), sl)
|
||||
elseif empty(ch)
|
||||
" Try swapping n and ch
|
||||
let [n, ch] = ['', n]
|
||||
|
||||
@@ -72,12 +72,38 @@ Examples:
|
||||
<Enter><Enter>**= Right-left alternating alignment around all equals signs
|
||||
|
||||
|
||||
Instead of finishing the command with a predefined delimiter key, you can type
|
||||
in a regular expression after `<CTRL-/>` or `<CTRL-X>` key.
|
||||
For example, if you want to align text around all occurrences of numbers:
|
||||
|
||||
- <Enter>
|
||||
- *
|
||||
- <CTRL-/> or <CTRL-X>
|
||||
- [0-9]\+
|
||||
|
||||
|
||||
While in interactive mode, you can adjust some of the alignment options using
|
||||
special shortcut keys listed below. The meanings of the options will be
|
||||
described in the following sections.
|
||||
|
||||
| Key | Option | Values |
|
||||
| ------- | ---------------- | ------------------------------------------ |
|
||||
| CTRL-I | indentation | shallow, deep, none, keep |
|
||||
| CTRL-L | left_margin | Input number or string |
|
||||
| CTRL-R | right_margin | Input number or string |
|
||||
| CTRL-D | delimiter_align | left, center, right |
|
||||
| CTRL-U | ignore_unmatched | 0, 1 |
|
||||
| CTRL-G | ignore_groups | [], [String], [Comment], [String, Comment] |
|
||||
| CTRL-O | mode_sequence | Input string of /[lrc]+\*{0,2}/ |
|
||||
| <Left> | stick_to_left | Set stick_to_left option |
|
||||
| <Right> | stick_to_left | Unset stick_to_left option |
|
||||
|
||||
|
||||
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.
|
||||
|
||||
" Using predefined alignment rules
|
||||
:EasyAlign[!] [FIELD#] DELIMITER_KEY [OPTIONS]
|
||||
@@ -424,6 +450,14 @@ in interactive mode with the special key CTRL-O)
|
||||
" Right, left, center, right, left, center, ...
|
||||
:EasyAlign **={ 'm': 'rlc' }
|
||||
|
||||
" Right, left, center, center, center, ... repeating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3={ 'm': 'rlc*' }
|
||||
|
||||
" Right, left, center, right, left, center, ... alternating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3={ 'm': 'rlc**' }
|
||||
|
||||
|
||||
Extending alignment rules *g:easy_align_delimiters*
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user