Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I tried to use yml, it requires NO TAB, ONLY SPACE policy. I realized I need a special setting for this.

Anyway, I can't live without tabs. So I want to make my VI behave like this.

  • When I press tab key, input many space characters aligned by tab stops.
  • When I press backspace key, delete many space characters aligned by tab stops.

How can I archive this functionality?

share|improve this question

Original vi: doesn't know about et, you could experiement with different values for ts (tabstop) and sw (shiftwidth, i.e. the amount << and >> indent a line or block of text). Basically, whenever sw is set to something lower (usually a fraction of) the value assigned to ts, indenting will use spaces instead of tabs. Beware that when a multiple of shifts add up to a full tabstop, a tab will be used in that place. Default is for both to be 8, and a number of other commands (such as expand), base their assumptions on that, so a text written with mixed tabs and spaces where ts has been tweaked may be misaligned when viewed lateron with a different setting for tabstop. To achieve your goal, you could first use /bin/expand to replace all tabstops with spaces in your existing text, then pull the text into vi, :set sw=4,ts=20, and try if these settings suit you. If they do, you can make them permanent by writing them into your .exrc

Another way, which would allow you to use tab and backspace the way you prefer (instead of shifting with << and >>) would be to allow yourself to write the text the way you prefer, and pipe it through /bin/expand prior to processing with yml, wither as part of your command chain, or from within vi itself:


In vim: you can use the et (expandtab) setting as already suggested, and even convert all tabs into spaces by uning a builtin (which has the advantage of knowing your tabstop settings, incase you tweaked them, without having to be told explicitely, as expand needs to).

:set et|retab

other interesting settings would include sts (softtabstop) and smarttab, with all these settings adapted to suit your needs, even ai (autoindent) would behave consistently and throw spaces instead of tabs.

:set et
:set sw=3
:set sts=3
:set smarttab
:set ai

or, in one line:

:set et sw=3 sts=3 smarttab ai

Again, once you agree with these settings, place them in your .vimrc

share|improve this answer
:set et 

You'll have to give up backspace and use < < instead.

You might be able to map backspace to unindent but there might be undesirable consequences.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .