Function editing with Vim throws IndentError

Timothy Grant timothy.grant at gmail.com
Tue Jul 22 18:11:29 EDT 2008


On Tue, Jul 22, 2008 at 2:02 PM, ptn <tn.pablo at gmail.com> wrote:

> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Are you editing someone else's code? If you are, my guess is that the file
uses tabs for indentation.

You may want to do ":set list" within Vim to test that theory. That should
show you what all the whitespace characters are.

-- 
Stand Fast,
tjg. [Timothy Grant]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080722/33675895/attachment-0001.html>


More information about the Python-list mailing list