I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying incorrect spacing for the line of code that I added. Gedit shows the code with the correct spacing. I know Gedit has the correct spacing because the Python code delivers errors if I change the code in Vim to be where it appears to belong within the Vim window. I have attached the Images below. The line that I added is the line that says: print "I am about to evaluate a factorial". I have included my short .vimrc file as well. Has anyone seen this? I have been using vim for months now and can't recall anything like this ever occuring.
It gets reset by the Python filetype plugin; from
" As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
This file is loaded every time a Python file is loaded. Personally I find adding indentation settings here a bit surprising though.
At any rate, to override this use this in your vimrc:
augroup python autocmd! autocmd FileType python setlocal noet ts=4 augroup end
This will get loaded after the ftplugin file, overriding the settings set there.
Personally, I would recommend against using tabs in Python files, as the community standard is to use spaces.
Solution for me was to add this line after the filetype plugin on into my
filetype plugin on autocmd FileType python setlocal noexpandtab shiftwidth=4 softtabstop=4