Function editing with Vim throws IndentError

ptn tn.pablo at gmail.com
Tue Jul 22 23:02:57 CEST 2008


Hi everybody,

I have a weird problem.  Say I have a .py file with some functions in
it, like this:

    # (...)
    def foo():
        print("bar")

When I open it and add a line to one of the functions,

    # (...)
    def foo():
        troz = "bar"
        print(troz)

I get the following traceback from the interpreter:

    Traceback (most recent call last):
      File "SOMEWHERE/example.py", line ??
        troz = "bar"
                          ^
    IndentationError: unindent does not match any outer indentation
level

And so I'm forced to rewrite the function entirely just to add the new
line.

I thought that my problem was the w option from formatoptions, so I
changed my .vimrc file to this:

    augroup filetype
      autocmd BufNewFile,BufRead *.txt set filetype=human
    augroup END
    autocmd FileType human setlocal formatoptions+=ta2w
    autocmd FileType lisp,scheme,python,c,java,vim setlocal
formatoptions-=ta2w

But the problem didn't go away.  I don't think this has anything to
do
with the tabs and spaces, because I have them set up like this:

    set tabstop=4 shiftwidth=4 expandtab

which is the standard way to handle them.

The scripts I load are: qbuf, TagList, indent/python.vim and a reduced
version of the standard python.vim

Could someone provide some pointers?

Thanks,

Pablo Torres N.



More information about the Python-list mailing list