Search code examples
pythonvimpython-mode

Vim getting indentation wrong for Python code (with the python-mode Plugin)


As shown in the following screen-cast, I demonstrate the strange behaviors of Vim when it comes to adding comments to Python code. Between Demo 1 and Demo 2, I was only starting the line of comments at different indentation level (inside a class definition).

Demo 1

enter image description here

Demo 2

enter image description here

The problem:

As demonstrated towards the end of screen-cast, only typing : in insert mode will get the indentation right.

An ideal solution would achieve:

That when starting a line of comment, please leave the indentation level correctly;


Solution

  • This sounds like a vim setting issue. Starting with vanilla vim, there is no indenting on each line, when I create a new line. If I create a file called .vimrc in my home directory. i.e. ~/.vimrc and put

    filetype indent plugin on

    in the file, I get what seems like expected indenting behavior. Does that work for you.