1

When I open a C file in vim, it seems to think I want 8 spaces worth of indentation, even though I specify my indentation preferences in .vimrc with the below:

set expandtab
set softtabstop=4
set shiftwidth=4
set autoindent

I also have:

filetype indent plugin on

The only fix I've come across so far is :set sw=4 in the buffer of the C file. I don't know why this works because I'm already setting that value in the .vimrc, so I can only guess that it's getting overwritten when the file-specific indentation settings are loaded. Unfortunately, deleting the filetype ... line from my .vimrc doesn't seem to help.

2
  • 5
    You can check the current value and where they were last set with :verbose set ts sts sw (ts being the short name for tabstop, sts for softtabstop, and sw for shiftwidth). Feb 21 at 0:01
  • To me that looks like a duplicate of this question. There are a lot of chances that :verbose set shiftwidth will point a ftplugin that you'll want to override
    – statox
    Feb 22 at 9:14
0

Thanks for the comments letting me know about :verbose. It turns out there was another vim config file on the remote machine I'm using hidden in /etc/. Unfortunately it's read only, and it seems like it has priority when it comes to this line:

autocmd FileType c setlocal tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab
1
  • You can probably get around it with vim -u ~/.vim/vimrc, but that's annoying.
    – D. Ben Knoble
    Feb 22 at 22:26

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