This is a follow up question to this post where I would jump to the definition of a variable in a vertical split for ctags. I’m currently using an lsp language server like so:

  local bufopts = { noremap=true, silent=true, buffer=bufnr }
  local servers = { 'tsserver', 'eslint', 'bashls','jsonls' } 
  for _, lsp in ipairs(servers) do
      lspconfig[lsp].setup {
          on_attach = function(client, bufnr)
            vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)

How can I set up the keymap so that I can jump to the definition in a vertical split here?


What I’m really asking here is how to combine vim commands with this vim.lsp.buf.definition

so by going over the docs and trying to implement one of the answers, I did this

on_attach = function(client, bufnr)        
  vim.keymap.set('n', 'gv', function() 
    vsplit vim.lsp.buf.definition
  end , bufopts)

but that didn’t work.

1 Answer 1


I would do:

lua vim.lsp.buf.definition()

It would look like this in init.lua

on_attach = function(client, bufnr)        
  vim.keymap.set('n', 'gv', function() 
  end, bufopts)
  • 1
    I’m not sure how to put that in the lua vim key mapping, please see update to question
    – abbood
    Commented May 9, 2023 at 14:39
  • I have updated my answer to translate it into lua. Commented May 9, 2023 at 15:05
  • I got this error now Cannot open file "buf.definition()" E5108: Error executing lua: [string ":lua"]:139: Vim(vimgrep):E480: No match: lsp stack traceback: [C]: in function 'cmd'
    – abbood
    Commented May 10, 2023 at 3:48
  • 1
    Nice! Well I have a place to start from: github.com/MunifTanjim/nui.nvim, this guy is used in github.com/SmiteshP/nvim-navbuddy which I use relgiously :)
    – abbood
    Commented May 10, 2023 at 19:17
  • 1
    I’m trying to do it, you can see where i’m stuck here
    – abbood
    Commented May 12, 2023 at 21:20

Your Answer

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

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