I am trying to improve a GitHub repository for Neovim called


It's a Lua repository that calls another Vim plugin repository, SirVer/ultisnips , a primarily Python-only library.

I basically need to call, in Python, UltiSnips_Manager._snips('completion text here', True)), and somehow get that list of string data back into Lua.

My plan was to imitate how UltiSnips does this, which is to call the Python object and assign its return value to a global Vim variable and then access that variable later. I just need to adapt the solution to work for Lua.

Here was my naive attempt at using Lua to call a Python function and send that data to a Vim variable so I could access it again, via Lua

import vim

snippets = UltiSnips_Manager._snips('completion text here', True)
snippet_names = [snipper.trigger for snippet in snippts]
vim.command(\"let g:_allowed_snippets = '%s'\" % snippet_names)


That doesn't work, because exec_python isn't a real Lua function, as far as I can tell. If there's a way to call Python within Lua in Neovim, could someone please explain how to do that? Or if there's a simpler way to call a Python script that is "known" to Vim and get the data back as a Lua object could someone explain how that could be done?

  • have you tried vim.fn.pyeval ?
    – Mass
    Nov 3, 2021 at 0:49
  • This is great, I forgot about that one. Thank you! Nov 3, 2021 at 1:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.