On 2006-07-13, Benji Fisher <[EMAIL PROTECTED]> wrote:
> On Wed, Jul 12, 2006 at 03:48:22PM -0700, John Reese wrote:
> > So there's this handy "[i" command that, when filetype=c, displays the
> > first line mentioning the identifier under the cursor, which will
> > often be its definition.  The especially handy thing about it is that
> > it knows about #include lines and will search through them as well
> > when looking for the first match.  You can also put the cursor over
> > the .h file between the quotes and hit "gf", and if the path and
> > suffixesadd options are set appropriately, it will jump you to the .h
> > file.
> > 
> > The point is, vim can be configured to know how to find C include
> > files and use them in various ways.
> > 
> > I was wondering if there was a way to get it to have a similar level
> > of knowledge about Python modules.  In C,
> > 
> >  #include "z.h"
> > will look for z.h in the current directory.  That's easy enough... the
> > Python equivalent is something like
> >  import z
> > 
> > But that actually just loads z.py from the current directory (or from
> > a bunch of other possible places, including system library directories
> > and directories listed in the PYTHONPATH environment variable) and
> > puts the name z into your namespace, and if you want to refer to
> > something defined in z.py, you qualify it:  z.someFunction().  A
> > Python-aware "[i" would know that if I have the cursor on the
> > someFunction in z.someFunction, then it needs to look for the word
> > someFunction in z.py.
> > 
> > There's also this from path import syntax:
> >  from a.b.c import z
> > 
> > which might mean that relative to the current directory there's a file
> > a/b/c/z.py that would need to be looked through if you used "[i".
> > 
> > So, anyway, this all seems very complicated, but I figured it wasn't
> > entirely out of the question that something was supported or
> > available, especially given the existence of the compiled-in Python
> > scripting option.  Does anyone know of anything to let vim understand
> > Python import syntax and use it for "[i" and similar commands?
> 
>      I am not sure if everything you want to do is possible or easy, but
> I suggest you start here:
> 
> :help include-search
> :help 'path'
> :help 'include'
> :help 'includeexpr'
> 
> See, for example, the ftplugin files for plaintex and tex.

A lot of this is already incorporated into the 
$VIMRUNTIME/ftplugin/python.vim plugin.  For example, gf works fine 
with Python import statements.  I don't know about [i because I 
never use it.  There are a number of Python plugins at vim.sf.net.  
One of those may have what you want if the standard python.vim 
plugin doesn't already make [i "just work".

HTH,
Gary

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Wireless Division
                             | Spokane, Washington, USA

Reply via email to