1

:echo pyeval('vim.current.window.col') works fine on a normal Neovim instance.

But if I start Neovim in diff mode or with the -u NONE option and try the same command, I get this error:

Error detected while processing function provider#python#Call:
line   18:
NameError("name 'vim' is not defined",)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/neovim/msgpack_rpc/session.py", line 181, in handler
    rv = self._request_cb(name, args)
  File "/usr/local/lib/python2.7/site-packages/neovim/api/common.py", line 237, in filter_request_cb
    walk(self._in, args, self, name, 'request'))
  File "/usr/local/lib/python2.7/site-packages/neovim/plugin/host.py", line 69, in _on_request
    rv = handler(*args)
  File "/usr/local/lib/python2.7/site-packages/neovim/plugin/script_host.py", line 148, in python_eval
    return eval(expr, self.module.__dict__)
  File "<string>", line 1, in <module>
NameError: name 'vim' is not defined
0

Any idea why this is happening? Not sure if this is related to Vim in general or Neovim.

  • 1
    Did you try adding import vim? – Martin Tournoij Sep 3 '17 at 17:59
  • Great that was the problem! I guess I should to read the vim python doc – Jerome Dalbert Sep 3 '17 at 18:08
2

Thanks to Carpetsmoker's comment, the solution was as simple as doing a :python import vim first.

The relevant doc is at :h python-vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.