nvim-neorg / neorg

Modernity meets insane extensibility. The future of organizing your life in Neovim.
GNU General Public License v3.0
6.32k stars 209 forks source link

Add hop-back keybind #1212

Open mbpowers opened 9 months ago

mbpowers commented 9 months ago

Issues

Feature description

I think it would be good to add a hop-back keybinding to the hop module. I imagine it could be as easy as mapping a key (default as backspace imo) to <cmd>bun<cr> or <cmd>bp<cr>.

Help

Yes

Implementation help

I don't use multiple buffers often so I expect my suggested implementation might have ways it could break, in which case I would need suggestions on a the best way to implement.

max397574 commented 9 months ago

just use <c-o>

mbpowers commented 9 months ago

If you navigate around the file in ways that affect the jumplist then you will have to many times to go back to the previous file and it will affect the cursor position which would ideally be preserved.

skbolton commented 9 months ago

I thinking binding to Backspace like vimwiki does would be awesome.

max397574 commented 9 months ago

I thinking binding to Backspace like vimwiki does would be awesome.

imo this isn't a good keybinding. We won't add certain keybindings just because that's what other tools use you could do this yourself though if such a keymapping would be added

@mbpowers true makes sense. I forgot the keybinding rn but there is something called "alternate file" to which you can instantly hop back. Perhaps that would do what you want. edit: <c-^> is the keybinding

mbpowers commented 9 months ago

<c-^> works fine once but then it cycles so if you go A -> B -> C pressing <c-^> will go C -> B -> C -> B.

I personally see it as giving users a way to easily achieve what they might want without having to know the intricacies of neovim bindings and buffers etc. or even if they know it will be repeated work as I think many will want this.

Thoughts on opt-in (could accept a key to bind to)? Or if the concern is it's not worth it to undergo this to add just a single binding, I think it would be nice to add as a note to the hop wiki.

champignoom commented 9 months ago

I lose track of buffers as well, not just in neorg but vim in general, so my solution was to customized the hop module so that <CR> opens links in new tabs, instead of trying to navigate through the invisible list of buffers.

max397574 commented 9 months ago

is that already a builtin option? to open the links in tabs? Otherwise I'd be nice if you could open a pr

mbpowers commented 9 months ago

:bp and :bun have unwanted side-effect as expected, I think the best way would be to store the path of the note that you are coming from in the destination note's buffer variables. This could be done when a hop is executed.

vhyrro commented 5 months ago

I would have to think about this one, more specifically how it would scale with complex jump trees (when you jump between files and links your path isn't always guaranteed to be linear).

It's true that the jumplist isn't informative enough as is. I think what would be more interesting is building up a tree of jumps which one could navigate. Then a simple hop-back would move up the tree, but we could provide more interesting navigation methods to go along with it.

With the introduction of luarocks we could import a library for rendering trees within Neovim. I believe NUI has something for that, so it might not even be that hard to implement :p

mtrajano commented 1 month ago

I was actually thinking about this recently. Another option for this would simply be to add to the tagstack every time you do a hop, similar to what the lsp go to definition does. That way you can traverse back with <C-t>. This would be a more native way to do it imo. If there's interest I can create a pr for this.