1

I am on CentOS 8.1 and using vim 8.0.1763. When I open a python file, e.g. vim tmp.py, I type tab and it inserts 4 spaces (see .vimrc below). When I type delete, it deletes all 4 spaces. I want it to delete only one space. I'm pretty sure this was the case in vim 7.4.629. In vim 8.0.1763, it deletes only one space if it is a .txt file but 4 if it is a .py file.

.vimrc

set number
filetype plugin on  
syntax on
set paste
set formatoptions-=tc
set ruler
set showmatch
set expandtab
set tabstop=4

Question :

How do I get vim to only delete one space in python files? I assume this is set in /usr/share/vim/vim80/syntax/python.vi, but I'm not particularly familiar with the vim language.

4
  • Do you have 'softtabstop' set to non-zero? Try setting to 0. Whether doing that will disable other functionality you want is something only you can answer. You should read the docs for it. (If this is the cause.) – B Layer Dec 22 '20 at 19:53
  • Setting softtabstop=0 does not help the situation – irritable_phd_syndrome Jan 22 at 16:18
  • Actually, setting softtabstop=0, does solve the problem. But I have to set it the session with the open file. I'm not sure why it won't get set when I add it to my .vimrc. – irritable_phd_syndrome Jan 22 at 16:56
  • My answer should address that. – B Layer Jan 23 at 7:13
3

What you're seeing is the result of having 'softtabstop' (alias 'sts') set to a non-zero value. It makes a lot of sense for this to be set in Python files where spacing matters since backspacing over individual spaces in indentation can lead to invalid Python.

If you really want to change it set 'sts' to 0. But you can't just put set sts=0 in your vimrc. It's being set well after your vimrc is sourced, i.e. after you load the file when the filetype (python) is identified.

There are a couple ways to set it but probably the most correct/appropriate is to put the setting in the file $VIMHOME/after/ftplugin/python.vim (where $VIMHOME is something like ~/.vim). You may have to create the file first.

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.