Reputation: 694
I have some lines like this
abc defg hijklmnopq
abc defghi jklmn opq
abc defgh ijklmno pq
I want them to be tabularized into at most three columns with at least 2 spaces in between columns, i.e.
abc defg hijklmnopq
abc defghi jklmn opq
abc defgh ijklmno pq
What Tabularize
command should I use in Vim?
Upvotes: 1
Views: 1097
Reputation: 22684
Given your input and output samples, the following command should do it.
:Tab /\s\+\zs\s/l1c0
You can abbreviate :Tabularize
to :Tab
to save a few keystrokes. The regular expression relies on a property of your data, namely that there is more than one space character separating the columns; otherwise it would be impossible to know which text belongs to which column.
We choose the final space as the delimiter character and then align the text left with a padding of 1. The \s
serves as the second padding space.
In the future, and as always, please consider the :help
. :help tabular
has extensive and very readable documentation that describes in detail all of the above.
Upvotes: 4