Search code examples
pythonvimautocompletedocstring

Python docstring with vim pythoncomplete is not displaying newlines for my own class functions


I am getting some unexpected results when trying to use Python Omni Completion on my own class functions. The docstring for the functions are not getting formatted correctly with line breaks as shown in the picture below:

Unexpected result

When I am importing modules from the standard python library I get the result I would expect:

Expected result

According to the python docstring conventions a newline in the source file should be interpreted as a newline. Does anyone know what's going on here and perhaps how to solve the issue?


Solution

  • Edit: I wrote an autocompletion, which should is much better than pythoncomplete: https://github.com/davidhalter/jedi-vim


    The Python Omni Completion of vim is pretty stupid. It's a simple script which parses the current file and imports all the others. This is pretty dangerous and shouldn't be done. However it works not that bad (but also not good at all).

    So really the difference between your two scenarios is, that the standard libraries are being imported. So are your files, but not the current file. If you used a second module named test2 and used:

    import test
    test.mydoc.prettyStr
    

    It should work.

    Your current file is being parsed. The parser is simple and not really good. The dostring parser is especially strange because of this line (line number ~290):

    docstr = docstr.replace('\n', ' ')
    

    You can modify it - just change this file: /usr/share/vim/vim73/autoload/pythoncomplete.vim Maybe it's in a different directory.

    Currently I'm in the process of writing a better autocompletion for python/vi (this is also the reason why I know this). But that's still quite some work. I hope I'll be ready with a Beta in a month. I try to keep you posted.