Leon R. Wood
Leon R. Wood

Reputation: 193

Import vim in python gives back errors

I read some articles about Vimscripting with python. I felt very interested. So I tried to figure out how to do vimscripting with python. But when I tried to import vim, it showed that the module vim wasn't installed. So I searched on the web, but still haven't find the module to install. I also tried pip to search automatically, still failed. Does anyone know where to find the module vim?

I am using fedora 17, and I have installed vim 7.3 and python 2.7.

Thanks in advance.

Here is the error message:

>>> import vim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named vim

Upvotes: 6

Views: 9839

Answers (3)

user9694578
user9694578

Reputation: 21

it do not work but this will work

:python from vim import *
:python command('echo "Hello World!"')

if you put vim.command(..

You get

Traceback (most recent call last):

File "<string>", line 1, in <module>
NameError: name 'vim' is not defined

Upvotes: 2

Samir Sadek
Samir Sadek

Reputation: 1690

Compile VI with python as described by hd1. You can find the documentation here:

http://vimdoc.sourceforge.net/htmldoc/if_pyth.html

If you want to test

export PYTHONPATH=$HOME/local/lib/python2.7/site-packages

Note that I installed all in local, this is why I use $HOME in PYTHONPATH

Run vi then, type

:python from vim import *
:python vim.command('echo "Hello World!"')

you should see "Hello World!" below.

Upvotes: 1

hd1
hd1

Reputation: 34677

It doesn't seem like you need to import it, just make sure your vim is compiled with python support. Check this using vim --version | grep +python. Further, it seems that the vim module is imported automatically when in vim, rendering your import line unnecessary.

Upvotes: 7

Related Questions