How do you use VIM to edit tabular data (tables)? Specifically, BIND (named) DNS db files

How about changing to spaces instead of tabs, and just using R (instead of i) to do your edits? That way you won't re-align anything (except for at first when you re-space everything).


File a feature request. VIM needs an option to display varying tab stops like is common in every word processor. So many people use vim as a word processor, I'm surprised this isn't already in there. I'm proposing that tabstop be modified to accept an array in place of an integer.


There is a dev-list patch for Vim that is said to implement variable tab stops. It's indicated{1} as being in beta stage.
Obviously this would involve compiling vim for the server(s) you want to use it on.

Another option would be to set up a custom file type that translates tabs into spaces delimited by some special character. You can set up autocommands to fire an import (ie convert to delimited columns) routine on read and an export routine (to convert back to tab-delimitation) on write, so it ends up working more or less transparently.
So for example the file

Column 1 header\tColumn 2 header\tcolumn 3 header
first row, column 1\tfirst row, column 2\tfirst row, column 3

would be viewed in vim as something like

Column 1 header»     «Column 2 header»     «Column 3 header
first row, column 1» «first row, column 2» «first row, column 3

This is more or less off the top of my head; there may well be a vimscript package that implements this. If not, it wouldn't be that hard to write. You just have to make sure that the column-delimiting characters —here "»" and "«"— aren't actually used in the file. For a bind config file, I would think that anything non-ASCII would be safe. For improved robustness I guess you could give vim a few options, and have it scan the file to find a set that wasn't present in the file, or just escape any of those characters that are.

It might be better to instead pad with characters that look like spaces{2} but aren't, like '\xa0' or '\u2002'; again this would only work correctly if the padding character wasn't present in the file, or you're having the import routine escape those that are.
Also I'm assuming familiarity with c-style backquoting: in the first part of the example, "\t" represents a tab character; the \x and \u sequences are hex and unicode character representations.

If you do end up implementing or finding something like this, please let me know.

{1}: http...groups.google.com/group/vim_dev/web/vim-patches?pli=1
{2}: http...www.cs.tut.fi/~jkorpela/chars/spaces.html
NB: obfuscated old-school reference style is due to my lack of reputation on this site.