Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/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.



Haystack[0] is pretty cool for something like this actually.

[0] https://haystackeditor.com/


Thanks, I hadn't seen this.


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”


this 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'.


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.


note the correct command is vim.api.nvim_buf_set_keymap or just vim.keymap.set




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: