Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I want to change tab key spacing to 4 spaces in VIM editor on CVS server.

I know the :set tabstop=4 command is used for that but it does not have a permanent effect. After restarting VIM it changes to 8 spaces by default. I want to change it permanently.

Thanks in advance.

share|improve this question
up vote 5 down vote accepted

you just need to add it to your .vimrc file.

set tabstop=2
share|improve this answer
where '.vimrc' file is located? – Hit's Dec 12 '11 at 6:42
~/.vimrc in your home directory – Nikhil Mulley Dec 12 '11 at 7:43
You can use vim -u path_to_vimrc too if you want to have it elsewhere. By default, vim reads the file from your home directory. – Luc M Dec 22 '11 at 18:56

Extend the answer:

  1. If you want to set it global, add set ts=2 to your ~/.vimrc - if it doesn't exist, just create new one.

  2. If you want to set tabstop for a specific file, use magic mode line in vim. Let's take C++ file as an example, add the line below in the beginning or the end of file: // vim: set ts=2

Read more about modeline in vim.

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.