How to columnize text with tabs (in vim or on the shell)
Set the tab display size to just larger than your longest field.
# original format
abcdefghijklmnop<Tab>field2
abcdefgh<Tab>field2
abcdefghijkl<Tab>field2
I have spaces!<Tab>field2
In Vim,
:echo len("abcdefghijklmnop") " Reports 16
:set noexpandtab tabstop=17
You can probably condense this to one command, but I don't know how. If you're running a modern Vim, :set list
will indicate hard tabs with a fancy character (which you can also configure). Otherwise they'll just show as ^I
(not what you want) or whitespace.
# displays like this
abcdefghijklmnop>field2
abcdefgh> field2
abcdefghijkl> field2
I have spaces!> field2
EDIT: An example from a real running vim!
The csv.vim - A Filetype plugin for csv files also supports tab-delimited files, and has :ArrangeColumn
and :UnArrangeColumn
commands for that.