(edit: Tabs were originally used with mono-space fonts to align *tables* on typewriters and in early printer formating. Tabs were not simply a replacement for multiple spaces, they actually aligned with specific columns using several fixed physical stops. The most common tab width was set to make data align every 8th character-column, so after a tab your first typed character would always be on column 9, 17, 25, 33,...etc. Much like a crude spreadsheet. eg. if you typed 'abc\td\te' d would be printed in column 9 and e in c.17.
Somewhere along the way just before desktop word processing was widely adopted by the general public some software was ignorantly or lazily written to interpret and display the tab char as equal to 8 spaces with no attempt at alignment. Not a big deal for a small one off, but some soon to be popular software [*coughwindows*] copied this and didn't bother to fix it which spread the 8 space interpretation far and wide leading to mis-education, many misunderstandings, poorly formatted text files, and spawned the spaces vs. tab wars.
For mono-space display, converting a tab to spaces should only be done if the conversion varies the number of spaces from 1-8 so the number of columns/printable-chars from beginning of line through the current conversion are a multiple of 8; `$columns%8 == 0`. Any simple conversion of tabs to spaces with fancy variable width font kerning will be ugly and misaligned, alignment is then only possible with variable width spaces. But tabs are already variable width whitespace intended for alignment of and so is essentially just replacing the space char with mini-tabs then converting one large tab to several several mini-tabs. ...so why convert at all?
As such the following rant based on disk space is factually incorrect.)
In a bygone era, tabs were sensibly used to keep files small, by replacing some number of space characters, typically as many as 8. It used to be that a megabyte was a lot of data. Nowadays, even a system with a tiny SSD disk would have 60,000 megabytes of storage. It's movies, pictures, and so forth, that chew up the disk space. Few people are going to type enough text so that tab/space compression is going to make a meaningful difference. So, you should decide on the use of tabs by personal preference.
Personally, I HATE tabs in files. They interfere with my automatic arrow presses, backspaces, x's, etc. I'm a Linux guy, and I support Red Hat Enterprise Linux at work. Vi (Vim) has always worked very well for me there. At home, I'm on Windows - I finally got sick of Notepad and switched to a real editor. GVIM's default of inserting tabs has been driving me bonkers. After a couple of hours of poking around the help (what an antiquated presentation that is!) and the web, I finally came up with a solution that works - setting vi compatibility:
which can be abbreviated as
Furthermore, I was able to cause GVIM to come up that way by adding these two lines line at the end of my Tcl file:
# \ vim:cp
Comments can be continued in Tcl, so Tcl won't see that last line.
Another key to know is that \t can be used to find or replace tabs that already snuck into your file. The technique I used to get rid of mine was:
/\t a<bs><sp><sp><sp><sp><sp><sp><sp><sp><esc> / .
using the backspace, space bar & escape, then repeating finds and changes while examining the results. Of course, you can do this with ":s".
The help says it is possible to save settings, _vimrc, and possibly other approaches that you could explore, if you have more patience than me. Since it took me hours to figure out this much, I thought I'd share it.
I'm going to choose to ignore your rant about Vim's help system, which I personally find the most useful and complete help of any computer program I've ever used. But, I admit sometimes it can be hard to find your way around. Maybe you just need to Learn to use help.
But I can't ignore:
- Setting 'compatible' turns off almost ALL of the improvements Vim has over plain old vi. It disables a ton of useful features and interferes with others. I'd NEVER recommend that to anybody.
- Getting Vim to stop inserting tabs is as easy as setting the 'expandtab' option, like this:
If you can't find it in the help, you can always try a web search next time. That would have led you to a few other places to find the answer, but also our own wiki page about Converting tabs to spaces.
Vim is definitely a pain to learn, and navigating this wiki is not particularly easy. However, typing "tab character" in the search box in the sidebar (without quotes) shows several pages including Converting tabs to spaces. That tip has the correct techniques mentioned by Fritzophrenic and Herb Wolfe. In a few days we will probably replace this page with a redirect to the existing tip. By the way, use
n to repeat a search (see Searching for a lot of useful information, although nearly all the tips assume use of Vim (not vi compatibility mode). JohnBeckett (talk) 12:09, May 28, 2014 (UTC)