Go to required lua file with a shortcut

Is there a way to navigate to a require ed file/function by placing the cursor on that line and hitting a keystroke?

E.g. suppose I have:


and that I place my cursor on that line. Can I easily navigate to that function in the file it is defined with a shortcut?


make sure you tell the LSP to discover the lua config/plugins/runtime directory, you can either snatch some part from this plugin or just use it in its entirety

1 Like

Thanks for the answer @elianiva. I have a follow-up question. I already have this setup for the sumneko Lua language server:

local lua_lsp_dir = "/home/mroavi/lsp-servers/lua-language-server/"
  cmd = {lua_lsp_dir .. "bin/Linux/lua-language-server", "-E", lua_lsp_dir .. "/main.lua"},
  capabilities = capabilities,
  settings = {
    Lua = {
      runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
      diagnostics = {globals = {"vim"}},
      workspace = {
        -- Make the server aware of Neovim runtime files
        library = {
          [vim.fn.expand "$VIMRUNTIME/lua"] = true,
          [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true

If I use the plugin you suggest, should I remove all this config and just add:

local luadev = require("lua-dev").setup()

? I tried this but it didnā€™t work.

Ohh I fixed it. The cmd was the only thing I had to specify properly. This config works now:

local lua_lsp_dir = "/home/mroavi/lsp-servers/lua-language-server/"
local luadev = require("lua-dev").setup({
  lspconfig = {
    cmd = {lua_lsp_dir .. "bin/Linux/lua-language-server", "-E", lua_lsp_dir .. "/main.lua"}

I also noticed that I was testing it too quickly after starting nvim. I forgot that the sumneko lua server takes a while to kick in.

@elianiva thanks again.