Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align at longest word

Tags:

vim

I have the following code:

a = 123
p.value 0.123
p.long.name = "abc"

How can I align each line like shown below in vim?

a           = 123
p.value     = 0.123
p.long.name = "abc"

Thanks for any hints.

like image 729
johannes Avatar asked Apr 25 '12 06:04

johannes


People also ask

How do you align long text in Word?

To align the text left, press Ctrl+L. To align the text right, press Ctrl+R. To center the text, press Ctrl+E.

What are the 4 alignment in MS Word?

There are four types of paragraph alignment available in Microsoft Word — left-aligned, center-aligned, rightaligned, and justified.


1 Answers

Without plugin:

:%s/=/                      &/
:%s/\%13c\s\+=/=

First command will insert spaces before first equal signs on all lines, second one will remove all spaces before an equal sign at 13th column. You could also use Visual block selection and <..... to shift left as many times as necessary.

However this is really unclean. With the tabular plugin you just type :Tab /=/ and this will do the work and the range will be calculated automatically (greatest range around the cursor in which all lines match the pattern).

like image 109
Benoit Avatar answered Sep 21 '22 18:09

Benoit