mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-11 19:33:50 -05:00
removes center-justification mode
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
vim-easy-align
|
||||
==============
|
||||
|
||||
A simple, easy-to-use Vim alignment plugin.
|
||||
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
||||
|
||||
Demo
|
||||
----
|
||||
@@ -21,7 +21,7 @@ vnoremap <silent> <Enter> :EasyAlign<cr>
|
||||
With the mapping, you can align selected lines with a few keystrokes.
|
||||
|
||||
1. `<Enter>` key to start interactive EasyAlign command
|
||||
1. Optional Enter keys to switch justficiation mode (default: left)
|
||||
1. Optional Enter keys to toggle right justification mode
|
||||
1. Optional field number (default: 1)
|
||||
- `1` Alignment around 1st delimiter
|
||||
- `2` Alignment around 2nd delimiter
|
||||
|
||||
@@ -13,13 +13,12 @@ let s:easy_align_delimiters_default = {
|
||||
\ '.': { 'pattern': '\.', 'margin_left': '', 'margin_right': '', 'stick_to_left': 0 }
|
||||
\ }
|
||||
|
||||
let s:just = ['L', 'R', 'C']
|
||||
let s:just = ['', '[R]']
|
||||
|
||||
function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left, recursive)
|
||||
let lines = {}
|
||||
let max_token_len = 0
|
||||
let max_just_len = 0
|
||||
let max_delim_len = 0
|
||||
let max_prefix_len = 0
|
||||
let max_tokens = 0
|
||||
let pattern = '\s*\(' .a:pattern. '\)\s*'
|
||||
for line in range(a:fl, a:ll)
|
||||
@@ -31,17 +30,21 @@ function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left,
|
||||
continue
|
||||
endif
|
||||
|
||||
" Preserve indentation
|
||||
if match(tokens[0], '^\s*$') != -1
|
||||
let tokens = extend([join(tokens[0:1], '')], tokens[2:-1])
|
||||
endif
|
||||
let max_tokens = max([len(tokens), max_tokens])
|
||||
let nth = match(tokens[0], '^\s*$') != -1 ? a:nth + 1 : a:nth
|
||||
|
||||
if len(tokens) < nth
|
||||
if len(tokens) < a:nth
|
||||
continue
|
||||
endif
|
||||
let nth = a:nth - 1 " 0-based
|
||||
|
||||
let last = tokens[nth - 1]
|
||||
let prefix = (nth > 1 ? join(tokens[0 : nth - 2], '') : '')
|
||||
let last = tokens[nth]
|
||||
let prefix = (nth > 0 ? join(tokens[0 : nth - 1], '') : '')
|
||||
let token = substitute(last, pattern.'$', '', '')
|
||||
let suffix = join(tokens[nth : -1], '')
|
||||
let suffix = join(tokens[nth + 1: -1], '')
|
||||
|
||||
if match(last, pattern.'$') == -1
|
||||
if !exists("g:easy_align_ignore_unmatched") || g:easy_align_ignore_unmatched
|
||||
@@ -53,8 +56,7 @@ function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left,
|
||||
let delim = matchlist(last, pattern)[1]
|
||||
endif
|
||||
|
||||
let max_token_len = max([len(token), max_token_len])
|
||||
let max_prefix_len = max([len(prefix), max_prefix_len])
|
||||
let max_just_len = max([len(token.prefix), max_just_len])
|
||||
let max_delim_len = max([len(delim), max_delim_len])
|
||||
let lines[line] = [prefix, token, delim, suffix]
|
||||
endfor
|
||||
@@ -62,7 +64,7 @@ function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left,
|
||||
for [line, tokens] in items(lines)
|
||||
let [prefix, token, delim, suffix] = tokens
|
||||
|
||||
let pad = repeat(' ', max_token_len - len(token) + max_prefix_len - len(prefix))
|
||||
let pad = repeat(' ', max_just_len - len(prefix) - len(token))
|
||||
if a:just == 0
|
||||
if a:stick_to_left
|
||||
let suffix = pad . suffix
|
||||
@@ -71,15 +73,6 @@ function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left,
|
||||
endif
|
||||
elseif a:just == 1
|
||||
let token = pad . token
|
||||
else
|
||||
let p1 = strpart(pad, 0, len(pad) / 2)
|
||||
let p2 = strpart(pad, len(pad) / 2)
|
||||
if a:stick_to_left
|
||||
let token = p1 . token
|
||||
let suffix = p2 . suffix
|
||||
else
|
||||
let token = p1. token .p2
|
||||
endif
|
||||
endif
|
||||
|
||||
let delim = repeat(' ', max_delim_len - len(delim)). delim
|
||||
@@ -101,7 +94,8 @@ function! s:do_align(just, fl, ll, fc, lc, pattern, nth, ml, mr, stick_to_left,
|
||||
endfunction
|
||||
|
||||
function! s:echon(l, n, d)
|
||||
echon "\rEasyAlign[". s:just[a:l] ."] (" .a:n.a:d. ")"
|
||||
echon "\r"
|
||||
echon "\rEasyAlign". s:just[a:l] ." (" .a:n.a:d. ")"
|
||||
endfunction
|
||||
|
||||
function! easy_align#align(just, ...) range
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
vim-easy-align *vim-easy-align* *easy-align*
|
||||
=========================================================================
|
||||
|
||||
A simple, easy-to-use Vim alignment plugin.
|
||||
A simple, easy-to-use Vim alignment plugin without too much ambition.
|
||||
|
||||
Author: Junegunn Choi
|
||||
Source: https://github.com/junegunn/vim-easy-align
|
||||
@@ -34,8 +34,7 @@ With this mapping, you can align selected lines with a few keystrokes.
|
||||
, Multi-line method arguments. CSV.
|
||||
| Table markdown
|
||||
|
||||
During the key sequence, <Enter> key will switch justification mode.
|
||||
(left -> right -> center)
|
||||
During the key sequence, <Enter> key will toggle right-justification mode.
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -49,11 +48,10 @@ Examples:
|
||||
<Enter>: Alignment around 1st colon
|
||||
|
||||
|
||||
EasyAlignRight, EasyAlignCenter *EasyAlignRight* *EasyAlignCenter*
|
||||
EasyAlignRight *EasyAlignRight*
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
*EasyAlignRight* and *EasyAlignCenter* are the right and center justified
|
||||
versions of EasyAlign command.
|
||||
*EasyAlignRight* is the right justified version of EasyAlign command.
|
||||
|
||||
|
||||
Partial alignment in blockwise-visual mode
|
||||
@@ -120,3 +118,4 @@ Then we get,
|
||||
# Quantity of grapefruits
|
||||
grapefruits: 3
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user