Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm usually a purist when it comes to vimming. I don't like remapping keys, or learning to rely on a bunch of plugins. I like to feel just as powerful on foreign boxen as I do on my own dev box. I do, however, believe in syntax files. Even though the solution may not be a syntax file (bindzone.vim is what I use), I want it bad enough to do whatever.

I regularly view or edit tab (or comma, but that would be a bonus) delimited data. I hate having to set my tabstop to some ridiculous number in order to have everything line up. Example: The BIND zone files are ~40+,6,2,5,15+. So, even though I could view them on a single screen, if I set ts=40, I cannot. I have been searching for a "dynamic tab size" solution for years, but no luck.

I hate that my only good way of editing or even visualizing tabular data is to scp it to my work station and open it in Open Office. There has to be a better way.

share|improve this question

6 Answers 6

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).

share|improve this answer
This is what I typically do. Unfortunately, I don't think it will work in his case... from a previous comment: "... I cannot use it for my DNS zone files. The admin would flip out (and rightfully so) if I alter every line of every file I touch..." –  Stobor Jun 28 '09 at 15:19
up vote 1 down vote accepted

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.

share|improve this answer
Actually it's feature request #22 on the list. vim.org/sponsor/vote_results.php –  Richard Bronosky Jul 27 '09 at 4:09

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.

share|improve this answer

I think you may be able to accomplish what you want using the Align plugin. (Apologies if you've already tried it.)

share|improve this answer
This looks like a very cool plugin. From what I can tell it modifies that file, rather than simply presenting it in a special way. Thank you for the lead. I will use this plugin for some things, but I cannot use it for my DNS zone files. The admin would flip out (and rightfully so) if I alter every line of every file I touch. –  Richard Bronosky Jun 15 '09 at 17:03

Did you know you are able to automatically set custom properties on files by defining a custom modeline? I realize this doesn't solve your problem, but will keep you from having to enter in your custom properties every time you want to align your file.

  • add to the top of your file '# vi:ts=40'
  • and remember to 'set modeline' in your .vimrc

This works in vi as well...

share|improve this answer
I think his problem is that this makes the lines ridiculously long. Especially when you consider some fields are only a couple of characters long. –  SpoonMeiser Jun 18 '09 at 11:56
SpoonMeiser is exactly correct. –  Richard Bronosky Jun 25 '09 at 5:20

A bunch of answers not entirely to the point, but maybe some of this fits somehow your working patterns:

Have a :%!sed -e 'whatever' that does what you need and put it in a comment somewhere in the file so you can paste it (I used to keep a :%!sort -u in a bind file for this kind of things).

If it's the same server all the time, have a (bash|perl|awk|sed) script somewhere on it that can be called similarly from within vim.

The :make command is also useful if you can put a makefile there.

Keep all the data in SQL and generate the files from there, while you edit certain tables or views (I'm only half joking).

Use the cut(1) and paste(1) commands (from within vim or from an auxiliary shell script) to emulate SQL views.

No vertical folds in vim are possible as far as I know, but block-select (with ctrl-V) is often useful.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.