Search code examples
vimtabular

Vim: different tabstop for different columns


I have some text file containing datas (like cvs) and formatted with tabs, but the columns doesn't have all the same size.

The default format in vim will be:

int1    longvalue1       string1
int2    anotherlongvalue2       string2

Can vim use diffent tabstops for different columns? The display would be

int1  longvalue1         string1
int2  anotherlongvalue2  string2

Solution

  • This feature (when done automatically by the editor) is commonly called Elastic tabstop. Such patches have been floated for inclusion in Vim (e.g. see here), but they are far from getting included in Vim (and there's little progress).

    As workarounds, you can either :set ts to a large value (causing huge gaps, though), or use a plugin like Align - Help folks to align text, eqns, declarations, tables, etc or Tabular - Vim script for text filtering and alignment to convert the Tabs to an appropritate amount of whitespace (maybe temporarily; convert back on :write).