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

By default, the space in vim is set to 8 spaces. How can we set the tab to 4 spaces in vim permanently?

share|improve this question
up vote 6 down vote accepted

Create a ~/.vimrc file with this line:

set ts=4 sw=4

This will set tabstops every 4 spaces and set the shiftwidth (that amount you indent) as 4 spaces also to match your tabstops.

share|improve this answer
this also works great! thank you – Steve Nov 16 '12 at 7:16

Make ~/.vimrc and add this:

set tabstop=4

Here are some other helpful ones:

syntax on " Syntax highlighting
set showmatch " Shows matching brackets
set ruler " Always shows location in file (line#)
set smarttab " Autotabs for certain code
set shiftwidth=4
share|improve this answer
this works great! thank you – Steve Nov 16 '12 at 7:17
thanks for the extra tip! – edward torvalds Jul 21 at 13:32

If you are just using vi (some people do not have vim available) put this in your .exrc file in your home directory or where you are editing code if you have/want a specific startup for a particular directory of code:

set shiftwidth=4 set tabstop=4 set expandtab "this might not work on all hosts" "quotes make nice comments in your .exrc files"

share|improve this answer

You must log in to answer this question.

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