Edit: This is what I ended up with, lua, nvim:
`buf_set_keymap('n', 'gds', '<c-w>v<cmd>lua vim.lsp.buf.definition()<CR>', opts)`
I made it a different map from the normal gd, so that I can choose to open in a new split or just jump to the one in my current window - I don't want a new split if e.g. a variable is define just 20 lines above my current one.
For any vim feature we can think of, somebody has implemented it. So I say this knowing that I’ve almost certainly just not seen it yet. But, it would be sort of nice if there was a key combo that basically said “just bring me to this definition if moving there would still leave some of the currently visible text on my screen (so I’m not jumping out of my current context and getting lost), but if it is any further of a jump, open a split”
Good one. In general a tricky thing to be aware of with vim: when I add a new variant that uses more characters, the ones with less characters will get a delay.
I presume one can tweak that delay even. But personally, I'll make all the shortcuts "symmetric", eventually. Indeed "gs" or "gv". In other cases, It'd become "gds", "gdd" or such. But "eventually", I try to change stuff more permanently once I see how I actually use it over a few days or weeks.
> As an aside, I also use this technique for navigating code with Vim, where a single shortcut goes to a definition of a function in a new pane
I was intrigued by this, and searched the author's github for their .vim. This is how they do that:
nnoremap gF <c-w>vgF
https://github.com/szymonkaliski/dotfiles/blob/357fc7c76ca86...
and
nnoremap <silent>gD :call CocActionAsync('jumpDefinition', 'vsplit')<cr>
https://github.com/szymonkaliski/dotfiles/blob/357fc7c76ca86...
---
Edit: This is what I ended up with, lua, nvim: `buf_set_keymap('n', 'gds', '<c-w>v<cmd>lua vim.lsp.buf.definition()<CR>', opts)`
I made it a different map from the normal gd, so that I can choose to open in a new split or just jump to the one in my current window - I don't want a new split if e.g. a variable is define just 20 lines above my current one.