mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-09 02:13:49 -05:00
Field index -> N-th parameter
This commit is contained in:
4
DEMO.md
4
DEMO.md
@@ -70,8 +70,8 @@ mysql:
|
|||||||
"user:pass":r00t:pa55
|
"user:pass":r00t:pa55
|
||||||
|
|
||||||
```
|
```
|
||||||
Using blockwise-visual mode or negative field index
|
Using blockwise-visual mode or negative N-th parameter
|
||||||
---------------------------------------------------
|
------------------------------------------------------
|
||||||
```ruby
|
```ruby
|
||||||
|
|
||||||
options = { :caching => nil,
|
options = { :caching => nil,
|
||||||
|
|||||||
@@ -166,8 +166,8 @@ my_object
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Using blockwise-visual mode or negative field index
|
Using blockwise-visual mode or negative N-th parameter
|
||||||
---------------------------------------------------
|
------------------------------------------------------
|
||||||
|
|
||||||
You can try either:
|
You can try either:
|
||||||
- select text around `=>` in blockwise-visual mode (`CTRL-V`) and `<Enter>=`
|
- select text around `=>` in blockwise-visual mode (`CTRL-V`) and `<Enter>=`
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -56,8 +56,8 @@ variant `:EasyAlign!`) for visual mode.
|
|||||||
| Mode | Command |
|
| Mode | Command |
|
||||||
| ------------------------- | ------------------------------------------------ |
|
| ------------------------- | ------------------------------------------------ |
|
||||||
| Interactive mode | `:EasyAlign[!] [OPTIONS]` |
|
| Interactive mode | `:EasyAlign[!] [OPTIONS]` |
|
||||||
| Using predefined rules | `:EasyAlign[!] [FIELD#] DELIMITER_KEY [OPTIONS]` |
|
| Using predefined rules | `:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]` |
|
||||||
| Using regular expressions | `:EasyAlign[!] [FIELD#] /REGEXP/ [OPTIONS]` |
|
| Using regular expressions | `:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]` |
|
||||||
|
|
||||||
### Concept of _alignment rule_
|
### Concept of _alignment rule_
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@ vnoremap <silent> <Enter> :EasyAlign<cr>
|
|||||||
With the mapping, you can align selected lines of text with only a few keystrokes.
|
With the mapping, you can align selected lines of text with only a few keystrokes.
|
||||||
|
|
||||||
1. `<Enter>` key to start interactive EasyAlign command
|
1. `<Enter>` key to start interactive EasyAlign command
|
||||||
1. Optional Enter keys to select alignment mode (left, right, or center)
|
1. Optional: Enter keys to select alignment mode (left, right, or center)
|
||||||
1. Optional field index (default: 1)
|
1. Optional: N-th delimiter (default: 1)
|
||||||
- `1` Around the 1st occurrences of delimiters
|
- `1` Around the 1st occurrences of delimiters
|
||||||
- `2` Around the 2nd occurrences of delimiters
|
- `2` Around the 2nd occurrences of delimiters
|
||||||
- ...
|
- ...
|
||||||
@@ -176,10 +176,10 @@ Instead of going into the interactive mode, you can type in arguments to
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Using predefined alignment rules
|
" Using predefined alignment rules
|
||||||
:EasyAlign[!] [FIELD#] DELIMITER_KEY [OPTIONS]
|
:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
|
||||||
|
|
||||||
" Using arbitrary regular expressions
|
" Using arbitrary regular expressions
|
||||||
:EasyAlign[!] [FIELD#] /REGEXP/ [OPTIONS]
|
:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
|
||||||
```
|
```
|
||||||
|
|
||||||
For example, when aligning the following lines around colons and semi-colons,
|
For example, when aligning the following lines around colons and semi-colons,
|
||||||
@@ -247,7 +247,7 @@ my_hash = { :a => 1,
|
|||||||
```
|
```
|
||||||
|
|
||||||
However, in this case, we don't really need blockwise visual mode
|
However, in this case, we don't really need blockwise visual mode
|
||||||
since the same can be easily done using the negative field index: `<Enter>-=`
|
since the same can be easily done using the negative N-th parameter: `<Enter>-=`
|
||||||
|
|
||||||
Alignment options
|
Alignment options
|
||||||
-----------------
|
-----------------
|
||||||
@@ -508,7 +508,7 @@ let g:easy_align_bang_interactive_modes = ['c', 'r']
|
|||||||
|
|
||||||
### Alignments over multiple occurrences of delimiters
|
### Alignments over multiple occurrences of delimiters
|
||||||
|
|
||||||
As stated above, "field index" is used to target specific occurrences of
|
As stated above, "N-th" parameter is used to target specific occurrences of
|
||||||
the delimiter when it appears multiple times in each line.
|
the delimiter when it appears multiple times in each line.
|
||||||
|
|
||||||
To recap:
|
To recap:
|
||||||
|
|||||||
@@ -364,12 +364,12 @@ function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth
|
|||||||
" Calculate the maximum number of tokens for a line within the range
|
" Calculate the maximum number of tokens for a line within the range
|
||||||
call s:max(max, { 'tokens': len(tokens) })
|
call s:max(max, { 'tokens': len(tokens) })
|
||||||
|
|
||||||
if a:nth > 0 " Positive field number
|
if a:nth > 0 " Positive N-th
|
||||||
if len(tokens) < a:nth
|
if len(tokens) < a:nth
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
let nth = a:nth - 1 " make it 0-based
|
let nth = a:nth - 1 " make it 0-based
|
||||||
else " -0 or Negative field number
|
else " -0 or Negative N-th
|
||||||
if a:nth == 0 && mode !=? 'l'
|
if a:nth == 0 && mode !=? 'l'
|
||||||
let nth = len(tokens) - 1
|
let nth = len(tokens) - 1
|
||||||
else
|
else
|
||||||
@@ -752,7 +752,7 @@ function! s:align(bang, first_line, last_line, expr)
|
|||||||
elseif n == '-' | let nth = -1
|
elseif n == '-' | let nth = -1
|
||||||
elseif empty(n) | let nth = 1
|
elseif empty(n) | let nth = 1
|
||||||
elseif n == '0' || ( n != '-0' && n != string(str2nr(n)) )
|
elseif n == '0' || ( n != '-0' && n != string(str2nr(n)) )
|
||||||
call s:exit('Invalid field number: '. n)
|
call s:exit('Invalid N-th parameter: '. n)
|
||||||
else
|
else
|
||||||
let nth = n
|
let nth = n
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ EasyAlign *:EasyAlign* *:EasyAlign!*
|
|||||||
vim-easy-align defines `:EasyAlign` command in the visual mode.
|
vim-easy-align defines `:EasyAlign` command in the visual mode.
|
||||||
(:EasyAlign! is the right-align version.)
|
(:EasyAlign! is the right-align version.)
|
||||||
|
|
||||||
| Mode | Command |
|
| Mode | Command |
|
||||||
| ------------------------- | ---------------------------------------------- |
|
| ------------------------- | -------------------------------------------- |
|
||||||
| Interactive mode | :EasyAlign[!] [OPTIONS] |
|
| Interactive mode | :EasyAlign[!] [OPTIONS] |
|
||||||
| Using predefined rules | :EasyAlign[!] [FIELD#] DELIMITER_KEY [OPTIONS] |
|
| Using predefined rules | :EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS] |
|
||||||
| Using regular expressions | :EasyAlign[!] [FIELD#] /REGEXP/ [OPTIONS] |
|
| Using regular expressions | :EasyAlign[!] [N-th] /REGEXP/ [OPTIONS] |
|
||||||
|
|
||||||
|
|
||||||
Interactive mode
|
Interactive mode
|
||||||
@@ -35,8 +35,8 @@ your `.vimrc`.
|
|||||||
With this mapping, you can align selected lines of text with a few keystrokes.
|
With this mapping, you can align selected lines of text with a few keystrokes.
|
||||||
|
|
||||||
1. <Enter> key to start interactive EasyAlign command
|
1. <Enter> key to start interactive EasyAlign command
|
||||||
2. Optional Enter keys to select alignment mode (left, right, or center)
|
2. Optional: Enter keys to select alignment mode (left, right, or center)
|
||||||
3. Optional field index (default: 1)
|
3. Optional: N-th delimiter (default: 1)
|
||||||
1 Around the 1st occurrences of delimiters
|
1 Around the 1st occurrences of delimiters
|
||||||
2 Around the 2nd occurrences of delimiters
|
2 Around the 2nd occurrences of delimiters
|
||||||
* Around all occurrences of delimiters
|
* Around all occurrences of delimiters
|
||||||
@@ -106,10 +106,10 @@ Instead of going into the interactive mode, you can type in arguments to
|
|||||||
`:EasyAlign` command.
|
`:EasyAlign` command.
|
||||||
|
|
||||||
" Using predefined alignment rules
|
" Using predefined alignment rules
|
||||||
:EasyAlign[!] [FIELD#] DELIMITER_KEY [OPTIONS]
|
:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
|
||||||
|
|
||||||
" Using arbitrary regular expressions
|
" Using arbitrary regular expressions
|
||||||
:EasyAlign[!] [FIELD#] /REGEXP/ [OPTIONS]
|
:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
|
||||||
|
|
||||||
For example, when aligning the following lines around colons and semi-colons,
|
For example, when aligning the following lines around colons and semi-colons,
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ Available options are as follows.
|
|||||||
| | | (right, left, center) |
|
| | | (right, left, center) |
|
||||||
| indentation | string | 'k' |
|
| indentation | string | 'k' |
|
||||||
| | | (keep, shallow, deep, none) |
|
| | | (keep, shallow, deep, none) |
|
||||||
| mode_sequence | string | (Depends on field index and |
|
| mode_sequence | string | (Depends on N-th param and |
|
||||||
| | | selected alignment mode) |
|
| | | selected alignment mode) |
|
||||||
|
|
||||||
There are 4 ways to set alignment options (from lowest precedence to highest):
|
There are 4 ways to set alignment options (from lowest precedence to highest):
|
||||||
@@ -407,7 +407,7 @@ settings as follows.
|
|||||||
Alignments over multiple occurrences of delimiters
|
Alignments over multiple occurrences of delimiters
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
As stated above, "field index" is used to target specific occurrences of
|
As stated above, "N-th" parameter is used to target specific occurrences of
|
||||||
the delimiter when it appears multiple times in each line.
|
the delimiter when it appears multiple times in each line.
|
||||||
|
|
||||||
To recap:
|
To recap:
|
||||||
|
|||||||
Reference in New Issue
Block a user