vim tabular only on the first match on the line?

后端 未结 4 976
忘了有多久
忘了有多久 2020-12-31 06:32

I\'m trying to format some python code with the tabular.vim plugin. It\'s currently a sqlalchemy declarative class, and looks something like this:

id     =           


        
4条回答
  •  佛祖请我去吃肉
    2020-12-31 07:19

    As per this answer, instead of creating a static mapping for each case, you can do this dynamically by setting up a vim command like this:

    command! -nargs=1 -range TabFirst exec  . ',' .  . 'Tabularize /^[^' . escape(, '\^$.[?*~') . ']*\zs' . escape(, '\^$.[?*~')
    

    With this command, if you wanted to align based on the first = then you could do:

    :TabFirst =
    

    Or, if you wanted to align on the first { you could do:

    :TabFirst {
    

    This supports range selections as well as Tabularize's smart selection.

提交回复
热议问题