C.Qian
C.Qian

Reputation: 169

Vim indentation with python getting wierd

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.

Upvotes: 0

Views: 954

Answers (1)

sudo bangbang
sudo bangbang

Reputation: 28229

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

Upvotes: 3

Related Questions