Support running as a command
Right now the only way to invoke this plugin is to use mappings (gl and gL by default). Because I don't align things very often, this is somewhat hard to memorize, and using a command which accepts a range is more useful (e.g. :LionLeft or :AlignLeft), similar to :Tabularize.
Any thoughts on this? Because everything is defined as a script-local function with s: adding this isn't so easy. I tried adding a command with :normal, and ended up with:
command! -range -nargs=1 AlignLeft exe "normal gvgl<args>"
command! -range -nargs=1 AlignRight exe "normal gvgL<args>"
But this isn't ideal as e.g. 50,100:AlignLeft , won't work, and you need to use AlignLeft \" instead of just :AlignLeft ". Not sure how to do it better though.
Personally I think it would be useful to at least facilitate/document this.
I have the same issue. I want a ex command to invoke alignment.
I wrote this in my vimrc,
function! s:Align(cmd, line1, line2, ...)
let l:save_cursor = getcurpos()
if a:0 == 0
let l:char = input("")
else
let l:char = a:1
endif
execute 'normal ' . a:line1 . 'GV' . a:line2 . 'G' . a:cmd . l:char
call setpos('.', l:save_cursor)
endfunction
command! -range -nargs=? AlignRight call <SID>Align('gL', <line1>, <line2>, <f-args>)
command! -range -nargs=? AlignLeft call <SID>Align('gl', <line1>, <line2>, <f-args>)
This works like :50,100AlignLeft , and if you omit parameter like :50,100AlignLeft, it asks.
But you still need to escape parameter when you use parameter style. (:AlignLeft \")