0
def main():

        todo=TODO()#this line shows one tab one sublime text
        print("The indentation is not right")# THIS ONE SHOWS TWO TABS

I got a wierd problem, I cannot use the vim to edit my python file anymore. The indentation above is the same I have, but I said the indentation is wrong. By the way, the first line which works right was edit by another computer. I use Fedora 23 for my operating system and default tab for vim is 8 space on any other files and just need a backspace to delete, when I create a .py file, the tab changes to 4 spaces and need backspace 4 times now I cannot use my vim to edit the files.

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
C.Qian
  • 155
  • 9
  • Could you provide more details on your situation? and could you provide the outputs of the following? `:set tabstop`, `:set shiftwidth` , `set softtabstop` – sudo bangbang Apr 22 '16 at 05:53
  • Also are you using any plugins for python? like `python-mode` or `pyflakes` or anything? – sudo bangbang Apr 22 '16 at 06:08
  • @sudobangbang I just checked it, all those three outputs were =8 when I created files other than .py, but they =4 when it is a .py file, my .vimrc didn't change this – C.Qian Apr 22 '16 at 12:07

1 Answers1

3

If you wanna use tabs that are 8 spaces wide and one tab for each indentation level, use

:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab

or put it in your .vimrc

set tabstop=8
set softtabstop=8
set shiftwidth=8
set noexpandtab

For setting this preferences specifically for python, put this in your vimrc

autocmd Filetype python setlocal ts=8 sts=8 sw=8

or

autocmd FileType python set tabstop=8|set shiftwidth=2|set expandtab

For more information, please read secrets of tabs in vim and indenting source code (vim wiki)

You can also read about it in the good old vim documentation

:help tabstop
:help softtabstop
sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
  • That really works in the vim, but when I write those in .vimrc, it doesn' work. why only .py has this problem – C.Qian Apr 22 '16 at 12:20
  • Are you using any vim plugins for python? – sudo bangbang Apr 22 '16 at 12:22
  • http://stackoverflow.com/questions/158968/changing-vim-indentation-behavior-by-file-type – sudo bangbang Apr 22 '16 at 12:23
  • setroubleshoot (1.1) setuptools (18.0.1) six (1.9.0) slip (0.6.4)slip.dbus (0.6.4)sosreport (3.2.0a1)SSSDConfig (1.13.3)urllib3 (1.13.1)yumex-dnf (4.1.3) – C.Qian Apr 22 '16 at 22:45
  • No @C.Qian I was talking about vim plugins or scripts. Did you try the commands I added to my question? ` autocmd Filetype python setlocal ts=8 sts=8 sw=8`? – sudo bangbang Apr 23 '16 at 04:56
  • Sorry for the late reply. I have remove the comments and your code works, THX! By the way, I found the reason cause this problem: Fedora 23 most recent update did makes change ,but I don't know which package did. – C.Qian Apr 24 '16 at 16:17
  • Maybe one of these did :vim-common x86_64 2:7.4.1718-1.fc23 updates 6.6 M vim-enhanced x86_64 2:7.4.1718-1.fc23 updates 1.2 M vim-filesystem x86_64 2:7.4.1718-1.fc23 updates 25 k vim-minimal x86_64 2:7.4.1718-1.fc23 updates 501 k – C.Qian Apr 24 '16 at 16:35
  • Awesome. Delighted to know that it helped you. – sudo bangbang Apr 24 '16 at 17:56