I'm trying to understand how can I use Lua to extend Neovim, following a baby steps approach. Something like:
-- ~/.config/nvim/lua/test.lua
local api = vim.api
local firstmodule = {}
function firstmodule.hello_world()
api.nvim_command('echo "hello world"')
end
return firstmodule
Then in my init.vim I import the module to a command:
command! Greet lua require 'test'.hello_world()
And I get a command :Greet
that prints hello world.
So far so good, but how can I get/use a string returned by a lua function, let's say:
function firstmodule.hello_string()
return 'hello world'
end
I try to call this function in my init.vim
:
let g:Myvar = v:lua.test.hello_string()
When I source the file, I get the errors:
E121: Undefined variable: v:lua
E15: Invalid expression: v:lua.test.hello_string()
How can I use that string returned by a lua function, let's say in my statusline?
E121: Undefined variable: v:lua
... Are you sure you're using NeoVim and not Vim? It seemsv:lua
is a NeoVim specific interface not present in Vim...