FAQ
Evening,

I'm an addicted vim user and don't really use the IDLE for anything more
than calculations where I'm too lazy to start KCalc. But one feature is
very pretty: the built-in help for function calls while you type. Like you
enter...

var1,var2=mystring.split(
...and the IDLE shows me a popup saying...
"S.split([sep [,maxsplit]]) -> list of strings

Is there a decent way to get that help into vim? Or like showing docstrings
or help that I get through pydoc on request? I've been working myself
through a pile of vim macros/plugins but couldn't find even one which
simplifies programming in Python. Further issues would be handling the
indentation - maybe a plugin which syntax colors different levels of
indentation so I don't have to use my plastic ruler on the screen. ;)
Perhaps some more experienced Python/Vim users have a tip which macro sets
help most here.

Thanks,
Christoph
--
~
~
".signature" [Modified] 1 line --100%-- 1,48 All

Search Discussions

  • Paddy at Nov 9, 2005 at 6:21 pm
    Hi,
    I am using gvim 6.4 which has Python colorising, and
    The menu tools->folding->fold method->indent

    :help folding
    May give you more info.

    Cheers, Paddy.
  • Jeffrey Schwab at Nov 9, 2005 at 7:29 pm

    Christoph Haas wrote:
    Evening,

    I'm an addicted vim user and don't really use the IDLE for anything more
    than calculations where I'm too lazy to start KCalc. But one feature is
    very pretty: the built-in help for function calls while you type. Like you
    enter...

    var1,var2=mystring.split(
    ...and the IDLE shows me a popup saying...
    "S.split([sep [,maxsplit]]) -> list of strings

    Is there a decent way to get that help into vim? Or like showing docstrings
    or help that I get through pydoc on request? I've been working myself
    through a pile of vim macros/plugins but couldn't find even one which
    simplifies programming in Python. Further issues would be handling the
    indentation - maybe a plugin which syntax colors different levels of
    indentation so I don't have to use my plastic ruler on the screen. ;)
    Perhaps some more experienced Python/Vim users have a tip which macro sets
    help most here.
    Vim is my editor of choice, too. I've even gone back to Vim from Eclipse.

    I believe what you want are "tags."

    http://www.vmunix.com/vim/tags.html

    I have not tried these in Vim yet, although I did use etags with Emacs
    (before I discovered the miracle of Vim).

    If you get context-sensitive help to work properly in Vim, please let me
    know!
  • Micah Elliott at Nov 9, 2005 at 9:28 pm

    On Nov 09, Christoph Haas wrote:
    I'm an addicted vim user and don't really use the IDLE for anything
    more than calculations where I'm too lazy to start KCalc. But one
    feature is very pretty: the built-in help for function calls while
    you type. Like you enter...

    var1,var2=mystring.split(
    ...and the IDLE shows me a popup saying...
    "S.split([sep [,maxsplit]]) -> list of strings
    The PIDA IDE <http://pida.berlios.de/index.php/PIDA:Features> claims
    to be able to do something like this. I have not used PIDA, but I too
    am a vim zealot and I think wrapping vim with extra functionality is a
    great idea, and I'll try it out when I get a chance.
    Is there a decent way to get that help into vim? Or like showing
    docstrings or help that I get through pydoc on request?
    You can set 'keywordprg' to something like "pydoc" to enable "K" to
    pull up the help. Its default setting is to open manpages for words
    under the cursor. I don't use it since I've got an interpreter shell
    sitting in the corner of most virtual desktops -- doesn't everyone?

    And ctags features are excessively prevalent in vim, and ctags works
    fine with python IME. You can create a tags file of your whole
    python installation.
    I've been working myself through a pile of vim macros/plugins but
    couldn't find even one which simplifies programming in Python.
    Matchit is a good one for %-matching:
    http://www.vim.org/scripts/script.php?script_id9
    Further issues would be handling the indentation
    Eric McSween wrote a python indenter:
    http://www.vim.org/scripts/script.php?script_id�4
    - maybe a plugin which syntax colors
    Sure, that's builtin. But Dmitry Vasiliev wrote some useful
    enhancements:
    http://www.vim.org/scripts/script.php?script_idy0
    Note that you'll have to enable some variables in the macro.
    syntax colors different levels of indentation so I don't have to use
    my plastic ruler on the screen.
    That's kind of a nice idea, and it should be an easy one to write (but
    I'm not volunteering). You could write it (:h syntax-highlighting) or
    maybe post a request to the vim mailing list <vim at vim.org>.

    Otherwise, folding would be useful for this. Pyfold might be helpful,
    though I haven't tried it:
    http://www.vim.org/scripts/script.php?script_idx1

    I like the ruler idea! Usually when I find myself straining to figure
    out what level I'm at it means it's time to refactor.

    --
    _ _ ___
    V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name
    " " """
  • Lonnie Princehouse at Nov 9, 2005 at 9:37 pm
    There is a Python folding script, as someone already mentioned. That
    will help you track indentation, although it's not perfect (iirc, long
    triple quoted strings cause folding malfunctions)

    I don't know of any way to get dynamic help about functions, although
    it seems like an ideal use of Vim's built-in Python interpreter and the
    vim python module.
  • Roman Roelofsen at Nov 9, 2005 at 11:52 pm

    Evening,

    Is there a decent way to get that help into vim? Or like showing docstrings
    or help that I get through pydoc on request? I've been working myself
    through a pile of vim macros/plugins but couldn't find even one which
    simplifies programming in Python. Further issues would be handling the
    Hi Christoph,
    Hi Vim users,

    The last 5 days I?ve been working on a code-completion/calltips plugin for
    vim. It?s working pretty good but not finished yet. I will anounce the first
    beta version on this mailling list. I hope during the next week.

    I recorded a swf-video so that you can take a look at the current status.
    Link: http://www.tuxed.de/vimpst/video.tar.gz

    Note that it is not necessary to generate symboltable files, etc. Everything
    is done "on demand". It is even possible to change the python implementation
    e.g. CPython, Jython, IronPython.

    It is also possible to add some "special feature" interceptor. Currently this
    is working for SQLObject:
    Lets say you have the class User and the attribute username is a alternate ID.
    Then, the method User.byUsername("...") will always return a User object.
    vimpst checks this and provides a suitable help.

    Regards,

    Roman
  • Christoph Haas at Nov 10, 2005 at 3:02 pm
    Hi, Roman et al...
    On Thursday 10 November 2005 00:52, Roman Roelofsen wrote:
    The last 5 days I?ve been working on a code-completion/calltips plugin
    for vim. It?s working pretty good but not finished yet. I will anounce
    the first beta version on this mailling list. I hope during the next
    week.

    I recorded a swf-video so that you can take a look at the current
    status. Link: http://www.tuxed.de/vimpst/video.tar.gz
    That is very impressive. I saw a similar plugin which had a big drawback:
    it didn't know the object type you need context help for. E.g. it offers
    you help for the .split method even though you are dealing with an object
    which does not have this method assigned. The great advantage of the IDLE
    is that it really understands Python. So it knows about object types you
    work with. I'm curious how you handle that. Perhaps the python features in
    Vim have that built-in. But Vim scripting looked even evil for me... and
    I've been working with Perl for a decade. :)

    Thanks for your contribution.

    Christoph
    --
    ~
    ~
    ".signature" [Modified] 1 line --100%-- 1,48 All
  • Sjdevnull at Nov 10, 2005 at 5:36 pm

    Christoph Haas wrote:
    But Vim scripting looked even evil for me... and
    I've been working with Perl for a decade. :)
    Vim scripting is nasty, but thankfully you don't really need to use it
    any more. You can write all your code in python with just a one-line
    hook to map it to a key.

    On the topic, I did something like this that you might find handy; the
    end result is that if you type
    a = myfunc(
    then the arguments for myfunc are displayed in the status line. If you
    hit <F1>, then the full python docs (if any) are shown (I'm working on
    having that show surrounding comments/docstrings for followed
    functions, but that code is busted up something awful at the moment and
    I haven't gone back to look at it).

    It's a complete work in progress, it could be terribly broken. I'll
    try to get it more polished/functional and put it up on sourceforge or
    somewhere.

    The order of lookups for prototypes is as follows:
    1. Try to follow tags; if there is a tag, grab the line in question
    (and any further lines until reaching a ":").
    2. Failing that, look in a help dictionary; I generated mine from the
    info version of the Python docs, using a simple Python script.
    3. Fail and show nothing.

    A couple of caveats:
    1. This uses the command area. So you either need to turn off
    "showmode" or set "cmdheight" to 2 or more; otherwise, the help text
    will be clobbered immediately by the INSERT prompt.
    2. The help dictionary is a dumb idea, it should be in a gdbm file or
    something--right now it increases the size of a running gvim by 600KB
    or so after the first time I use the help function (and that first
    lookup is slow) because it's reading it a huge chunk of the vim docs.
    3. The code abuses the preview window, which I don't care about because
    I never use the preview window for anything else. I would expect that
    the user-visible effect of this will be to close any preview windows
    you have open any time you type an open-paren.
    4. It really works best in gvim; in a command-line vim it may recenter
    your windows and have other jumpiness. I tried for a while to figure
    out a workaround and gave up.

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    Vim code (put in ~/.vimrc)

    function! DocParen()
    py vimrc.print_help()
    return "("
    endfunction
    inoremap <F1> <C-O>:echo b:helpString<CR>
    inoremap ( <C-R>=DocParen()<CR><C-O>:echo b:shortHelp<CR>

    Python code (put in ~/.vim/vimrc.py)
    import vim

    def cur_x():
    return vim.current.window.cursor[1]


    def cur_y():
    return vim.current.window.cursor[0]

    def snag_help(current):
    vim.command("let v:errmsg=''")
    vim.command("silent! ptag %s"%current)
    if vim.eval("v:errmsg"):
    return ""
    vim.command("silent! winc P")


    help = vim.current.line.strip()

    if help.startswith("def") or help.startswith("class"):
    while not vim.current.line.strip().endswith(":"):
    vim.command("+")
    help = help + " "+vim.current.line.strip()


    try:
    help = help.split("def ", 1)[1]
    except:
    pass
    if help.endswith(":"):
    help = help[:-1]
    vim.command("silent! winc p")
    vim.command("silent! winc z")
    return help


    def print_help():
    global docDict
    if not docDict:
    import pyhelp
    docDict = pyhelp.docDict
    currWord = vim.current.line.strip()
    for ch in " .":
    try:
    currWord = currWord.split(ch)[-1]
    except:
    pass


    help snag_help(currWord)


    if not help:
    try:
    help = docDict[currWord]
    except:
    help = ""
    if help.find("(self, ") > 0:
    help=help.replace("(self, ", "(")
    if '"' in help:
    help=help.replace('"', '\\"')
    shortHelp = help
    if len(vim.windows) == 1:
    truncate = vim.current.window.width-20
    else:
    truncate = int(vim.eval("&columns")) -1
    if len(help)>truncate:
    shortHelp=help[:truncate]
    vim.command('let b:helpString="%s"'%help)
    vim.command('let b:shortHelp="%s"'%shortHelp)
  • Sjdevnull at Nov 10, 2005 at 5:40 pm

    sjdevnull at yahoo.com wrote:
    2. Failing that, look in a help dictionary; I generated mine from the
    info version of the Python docs, using a simple Python script.
    Which is as follows (run on all the python-lib*info* files and it'll
    generate a file called "output"; rename that to ~/.vim/pyhelp.py)

    import sys

    docDict = {}

    for file in sys.argv[1:]:
    lines = open(file, "r").readlines()
    for i in range(len(lines)):
    line = lines[i].strip()
    if line.startswith("`") and "(" in line and line.endswith("'"):
    line = line[1:-1]
    kv = line[0:line.find("(")]
    j = i
    while j < len(lines) and lines[j+1].startswith(" "):
    j = j+1
    line = line + " "+lines[j].strip()

    if kv and kv not in docDict:
    docDict[kv] = line

    keys = docDict.keys()
    keys.sort()
    for k in keys:
    print docDict[k]
    open("output", "w").write("docDict="+`docDict`)
  • Micah Elliott at Nov 10, 2005 at 7:36 pm

    On Nov 10, sjdevnull at yahoo.com wrote:
    vim... I'll try to get it more polished/functional and put it up on
    sourceforge or somewhere.
    Change "sourceforge or somewhere" to:
    http://www.vim.org/scripts/add_script.php

    --
    _ _ ___
    V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name
    " " """
  • Jeffrey Schwab at Nov 10, 2005 at 1:53 am

    Roman Roelofsen wrote:
    Evening,

    Is there a decent way to get that help into vim? Or like showing docstrings
    or help that I get through pydoc on request? I've been working myself
    through a pile of vim macros/plugins but couldn't find even one which
    simplifies programming in Python. Further issues would be handling the

    Hi Christoph,
    Hi Vim users,

    The last 5 days I?ve been working on a code-completion/calltips plugin for
    vim. It?s working pretty good but not finished yet. I will anounce the first
    beta version on this mailling list. I hope during the next week.

    I recorded a swf-video so that you can take a look at the current status.
    Link: http://www.tuxed.de/vimpst/video.tar.gz

    Note that it is not necessary to generate symboltable files, etc. Everything
    is done "on demand". It is even possible to change the python implementation
    e.g. CPython, Jython, IronPython.

    It is also possible to add some "special feature" interceptor. Currently this
    is working for SQLObject:
    Lets say you have the class User and the attribute username is a alternate ID.
    Then, the method User.byUsername("...") will always return a User object.
    vimpst checks this and provides a suitable help.
    Right on! Good luck! Can't wait!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 9, '05 at 3:09p
activeNov 10, '05 at 7:36p
posts11
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase