I've looked through various answers which imply that setting the following in .vimrc would be appropriate to force tab insertions to become spaces.

filetype plugin indent on
" On pressing tab, insert 2 spaces
set expandtab
" show existing tab with 2 spaces width
set tabstop=2
set softtabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2

However, when I attempt to use 2 spaces, it continues to default to 4 spaces per tab. I have tried moving set expandtab to the bottom of these declarations. I have tried removing the softtabstop declaration. I've scoured the various answers given to other questions as well.

2 Answers 2


Have you sourced your .vimrc since making these changes? When having vim open just type source ~/.vimrc (assuming it is in it's default location)

EDIT: This could help too

  • It looks like my problem was indeed a lack of sourcing. I had read that the file would be automatically sourced when you edited it, and indeed I did see some changes to my VIM when initially creating the .vimrc file. Thank you for your answer!
    – Chris Snow
    Commented Jul 30, 2017 at 2:38
  • @Gleland, Is there a way to only set tabs to 2 spaces, for markdown files only?
    – alpha_989
    Commented Mar 11, 2018 at 23:43
  • @alpha_989 this should help stackoverflow.com/questions/158968/…
    – Gleland
    Commented Mar 13, 2018 at 2:40

This should fix your problem. It has more options, but two first lines are most important.

set tabstop=2 softtabstop=2 shiftwidth=2
set expandtab
set number ruler
set autoindent smartindent
syntax enable
filetype plugin indent on
  • 2
    Can you explain what this does and how it solves a problem that OP solved 6 years ago?
    – romainl
    Commented Aug 30, 2023 at 14:15
  • "two first lines are most important" - you could easily improve your answer if you removed the other lines.
    – Friedrich
    Commented Aug 31, 2023 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.