Simple text alignment
From Vim Tips Wiki
created August 23, 2002 · complexity basic · author Jahagirdar Vijayvithal S · version 5.7
Some times one would like to reformat text like:
a=1; foo=2; longstring=1; c=2
a =1; foo =2; longstring =1; c =2;
This is how we achieve it
This is what it does
0 goes to first column f= finds next occurrence of = on current line 20i<Space><Esc> inserts 20 spaces before = 0 goes back to first column 20l forward 20 column vf=hx deletes everything up to the = sign
Any lining up, alignment, etc - just leave it to Dr. Chip Campbell's Align.vim (search for it here)
I see a BIG drawback! What will it do in the following case?
int my_very_informative_variable_name = 0;
the result will be:
int my_very_informat= 0;
The correct way to solve this problem is to find the longest var in the list (selected lines) and align accordingly.
Some mappings and a python script for alignment. http://www.ophinity.com/code/wrangling/index.html#lineUp
- humans can understand python
- you need to have a python interpreter on your box
- it's not as sophisticated as dr. chips script
You can save a couple keystrokes without visual mode.
And a couple more by using the goto-column movement :help bar:
And finally, you can fire off something like
to do this for a bunch of lines.
works well of you have softtabs set to use spaces. (Or using :retab)
This will align based on next tab columns. Neat enough for me.
Personally I'd shell out and use column for this, but obviously requires having column installed!!
:'<'>! column -ts=
Allow me to make a small but important modification to the last command:
:'<'>! column -ts= -o=
Otherwise, the "=" sign would be removed from the output. It's a very good replacement for the Tabularize plugin! At least for simple stuff like that.