Just had a quick (and probably stupid) question about indentation. When I try editing a script, one of my settings seems to "freeze" the indentation several tabs in, and I can't figure out what is doing it. For example, I'm working on a Python file, and have

def example():
    x = 1
    y = 2
    print("The sum of {0} and {1} is {2}"
          .format(x, y, x+y)

    z = 3
    zz = 4

So the problem is when I press enter to type variable z, the indentation automatically moves all the way over to where the left parentheses is on the print statement, so I end up having to hit backspace all the way to the first level of indentation. Then I hit enter again, and instead of placing the cursor under "z", it places it under the left parentheses. Here are all the indentation settings, as well as tangential ones, on my .vimrc:

filetype indent plugin on
set autoindent
set nostartofline
set linebreak
set wrap
set shiftwidth=4
set softtabstop=4
set expandtab
set shiftround
filetype indent on

Any help would be greatly appreciated!

Edit: found it, it was filetype indent on. Sorry, I'm a big time beginner, and apparently Vim's indent scheme can collide with that of other languages? I've obviously got some research to do, but thanks for the help and any suggestions!

  • 2
    Welcome to Vi and Vim! If you found the answer to your question, you should post it as an answer rather than an edit to your question.
    – filbranden
    Commented Jul 2, 2020 at 1:06

1 Answer 1


Looks like you are missing the closing round brace for print().

print("The sum of {0} and {1} is {2}"
      .format(x, y, x+y))

It should indent correctly after fixing that.

  • Sorry, the site autoformatted that for me. Your example is what I have typed in, but one of my tab settings is causing everything under that left parentheses to automatically tab everything under it to that depth, causing me to backspace for every new line. Commented Jul 1, 2020 at 21:43
  • Check :set filetype and :set indentexpr to see if vim is actually loading the python indenting. You can read up on indent and ft at :help indent.txt and :help filetype.txt. Commented Jul 3, 2020 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.