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 = db.Column(db.Integer, primary_key=True)
status = db.Column(db.Integer, nullable=False, default=3)
...etc...
I'd like to be able to align only the very first equals sign in the list.
id = db.Column(db.Integer, primary_key=True)
status = db.Column(db.Integer, nullable=False, default=3)
...etc...
Just a regular
: Tabularize /=
seems to match everything, and everything goes crazy.
Thanks very much in advance!
You can use this command:
The pattern only matches the first
=
.You can add these two line to
~/.vim/after/plugin/TabularMaps.vim
Next time, simply run:
If you don't need spaces around
=
, run this:Excellent plugin to do it: vim-easy-align.
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:
With this command, if you wanted to align based on the first
=
then you could do:Or, if you wanted to align on the first
{
you could do:This supports range selections as well as Tabularize's smart selection.
The suggestions above are good, but in this case they are a little too complicated and require too much typing. How about:
This works just fine -- match the first equal sign and everything after it, aligned left (default, which works just fine!).