14

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. If anyone can help me out that would be amazing.

5

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 Jul 30 '17 at 2:38
  • @Gleland, Is there a way to only set tabs to 2 spaces, for markdown files only? – alpha_989 Mar 11 '18 at 23:43
  • @alpha_989 this should help stackoverflow.com/questions/158968/… – Gleland Mar 13 '18 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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