From 614222655bf29ab04dcb1766d012314fc2c16cc2 Mon Sep 17 00:00:00 2001 From: sslater11 <43177940+sslater11@users.noreply.github.com> Date: Fri, 20 Sep 2019 19:42:42 +0100 Subject: [PATCH 1/2] Made live mode more intuitive to use We can press any of these keys several times to see our alignments change in real time I changed the Enter key to accept the changes, instead of the old Ctrl-P, which felt clunky and odd. We now cycle through different alignments using the 'a' key. We can enter regex mode by typing / at an point. We can align by columns 1-9 by pressing the keys 1-9 at any time. We can say align by ALL columns by pressing '*' at any time. We can align just the last column by pressing '-' at any time. --- autoload/easy_align.vim | 43 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 795ea31..d314272 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -677,12 +677,36 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, bvis) let n = strpart(n, 0, len(n) - 1) endif elseif c == 13 " Enter key + " simon was here + " Accept the changes and exit. Same as + if s:live + if !empty(d) + let ch = d + break + else + let s:live = 0 + endif + else + let s:live = 1 + endif + " simon was here + " Cycle through the different alignments using letter 'a'. + elseif ch == 'a' || ch == 'A' let mode = s:shift(a:modes, 1) if has_key(opts, 'a') let opts.a = mode . strpart(opts.a, 1) endif elseif ch == '-' if empty(n) | let n = '-' + " simon was here + " Override the * option to align all columns. + elseif n == '*' | let n = '-' + elseif n == '**' | let n = '-' + " simon was here + " Override the numbers the user typed for single column aligning. + " Allows us to press - after we have already typed a number. + elseif ( n > '0' && n <= '9') + let n = '-' elseif n == '-' | let n = '' else | let check = 1 endif @@ -690,12 +714,20 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, bvis) if empty(n) | let n = '*' elseif n == '*' | let n = '**' elseif n == '**' | let n = '' + " simon was here + " Override the numbers the user typed for single column aligning + " Allows us to press * after we have already typed a number. + elseif ( n > '0' && n <= '9') + let n = ch + " simon was here + " Override if they aligned the last column + elseif n == '-' | let n = '*' else | let check = 1 endif - elseif empty(d) && ((c == 48 && len(n) > 0) || c > 48 && c <= 57) " Numbers - if n[0] == '*' | let check = 1 - else | let n = n . ch - end + " simon was here + " User typed a number to choose which column to align. + elseif ((c == 48 && len(n) > 0) || c > 48 && c <= 57) + let n = ch elseif ch == "\" call s:shift_opts(opts, 'da', vals['delimiter_align']) elseif ch == "\" @@ -754,7 +786,8 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, bvis) else silent! call remove(opts, 'a') endif - elseif ch == "\" || ch == "\" + " simon was here - Enter regex using '/' key + elseif ch == "\" || ch == "\" || ch == '/' if s:live && regx && !empty(d) break endif From f6b149595fa00fe32ddab22df5c0a8b2622d3c84 Mon Sep 17 00:00:00 2001 From: sslater11 <43177940+sslater11@users.noreply.github.com> Date: Fri, 20 Sep 2019 21:38:34 +0100 Subject: [PATCH 2/2] Start livemode with "align all columns" by default Probably personal preference, but I tend to want to match all the columns up every time I use this, so I set it to default. Not sure if this is the proper way to do it, but it seems to work well for me at least :). --- autoload/easy_align.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index d314272..452e9bd 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -1149,6 +1149,9 @@ function! s:align(bang, live, visualmode, first_line, last_line, expr) if bypass_fold | let &l:foldmethod = 'manual' | endif if empty(n) && empty(ch) || s:live + " simon was here + " Start live mode with 'align all columns' enabled by default + let n = '*' let [mode, n, ch, opts, regexp] = s:interactive(range, copy(modes), n, ch, opts, rules, vis, bvis) endif