0

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)
          end
      }
  end

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

update

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

1

I would do:

vsplit
lua vim.lsp.buf.definition()
on_attach = function(client, bufnr)        
  vim.keymap.set('n', 'gv', function() 
    vim.cmd([[
vsplit
]]
    vim.lsp.buf.definition()
  end, bufopts)
8
  • 1
    I’m not sure how to put that in the lua vim key mapping, please see update to question
    – abbood
    May 9 at 14:39
  • I have updated my answer to translate it into lua. May 9 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
    May 10 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
    May 10 at 19:17
  • 1
    I’m trying to do it, you can see where i’m stuck here
    – abbood
    May 12 at 21:20

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.

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