Remapping CTRL-W <foo> combinations

In my lsp on_attach function, I have a mapping of gd to vim.lsp.buf.definition. However, I can’t go to definition in a new split window. The default vim mapping for this is CTRL_W-d, ie “press ctrl-w, then press d”. However I’m not sure how to map multi-key combinations like this. What’s the correct syntax for remapping this to use the lsp’s definition?

In your mapping, you could first split the window and then go to definition.

Not sure if you asking how to define keystroke chain or how to implement split and go to definition. It should be something like that:

vim.keymap.set('n', '<c-w>d', function()
  vim.cmd.split()
  vm.lsp.buf.definition()
end)

It’s not ideal as sometimes you can have multiple definitions and if there is no definition you will end up with split anyway. But that should show you have you can start with this binding.

1 Like