Vim Tips Wiki
Advertisement

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:

:set compatible

which can be abbreviated as

:se cp

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.

Comments

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: :set expandtab or :set et.

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.

--Fritzophrenic (talk) 14:50, May 27, 2014 (UTC)


In addition, there is the :retab command, which is useful for changing the size of tabstops or stripping tabs, once you have expandtab set. ---- Herb Wolfe (talk) 20:50, May 27, 2014 (UTC)


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)


Advertisement