vim & python

C. Laurence Gonsalves clgonsal at alumni.uwaterloo.ca
Fri Mar 26 11:45:45 EST 2004


On 4 Mar 2004 18:53:18 -0800, sb <spam_bait101 at yahoo.com> wrote:
>  Thanks, but that is more like a very abbreviated tutorial. Where can I
>  can the real documentation? It seems like the python built into vim is
>  different. For example, doing
>  
> :py import sys
> :py dir(sys)
>  
>  produces no output. Odd.

The statement 'dir(sys)' doesn't produce any output in Python. What's
confusing you is that the interactive mode of the python interpreter
prints the values of expression statements, if the value is not None.
That's a feature of the interactive mode though, not of Python, the
language.

You can verify this for yourself by creating a little script:

  import sys
  dir(sys)

Copy the above to a file, test.py. The lines should not be indented, of
course. Then execute 'python test.py' from the shell. Note the lack of
output.

In vim, just as in Python scripts, if you want output you need to
explicitly ask for it. So try the following in vim:

  :py import sys
  :py print dir(sys)

BTW, the "python built into vim" is really just the normal python
interpreted, embedded in vim. Everything you know about the Python
language still holds. The main differences are that it doesn't have the
same sort of "interactive mode" that the python interpreter has, and you
have access to he vim module. Documentation for the latter can be found
by executing ':help python-vim'. Yes, the documentation is brief, but it
is fairly complete, as far as I can tell.



More information about the Python-list mailing list