Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running as a command #26

Open
arp242 opened this issue Apr 15, 2018 · 1 comment
Open

Support running as a command #26

arp242 opened this issue Apr 15, 2018 · 1 comment

Comments

@arp242
Copy link

arp242 commented Apr 15, 2018

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.

@hayatogh
Copy link

hayatogh commented Nov 4, 2019

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 \")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants