4 ms·
Slightly unrelated: > 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
by berkes 2y ago
Slightly unrelated:
> 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/357fc7c76ca86042effba7836fc8b4101057d285/Dotfiles/vimrc#L570 https://github.com/szymonkaliski/dotfiles/blob/357fc7c76ca86...
and
nnoremap <silent>gD :call CocActionAsync('jumpDefinition', 'vsplit')<cr>
https://github.com/szymonkaliski/dotfiles/blob/357fc7c76ca86042effba7836fc8b4101057d285/Dotfiles/vim/after/plugin/coc.vim#L56 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.
- hyperbrainer 2y agoHaystack[0] is pretty cool for something like this actually. [0] https://haystackeditor.com/ https://haystackeditor.com/
- delano 2y agoThanks, I hadn't seen this.
- bee_rider 2y agoFor 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”
- deleted 2y ago[deleted]
- hellojebus 2y agothis is great, added this to my nvim config. But changed it to 'gv' as 'gds' added a little bit of lag when I wanted to use 'gd'.
- berkes 2y agoGood 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.
- jonaustin 2y agonote the correct command is vim.api.nvim_buf_set_keymap or just vim.keymap.set