MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
825 stars 23 forks source link

Add way to open nth result #223

Closed MagicDuck closed 2 months ago

MagicDuck commented 2 months ago

https://www.reddit.com/r/neovim/comments/1el3g8i/comment/ljjnw30/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

comments from reddit:

nuriaion:

I really like this plugin it's slowly taking over all my search needs! :) One short idea i had if it would be possible to add a mark to first few results, so that i could create some bindings to directly open this result. This way i could make some keybindings to directly open the xth result.

MagicDuck:

Maybe could be done as a count on the Open Location action.

So: 1,o. Open first match 2,o Open second match … and so on And of course you could rebind those if desired.

MagicDuck:

I suppose one rebind to shorten could be just: ,1 ,2 ,3

nuriaion:

I really like the idea of the count on o. Maybe it would also need the number on each location because else you have to search

MagicDuck commented 2 months ago

hmm, have it working and showing the result line number, but not sure how practical it is...

image

also added this options to config it:

  resultLocation = {
    -- whether to show the result location number
    showNumberLabel = true,

    -- position of the number when visible, acceptable values are:
    -- 'right_align', 'eol' and 'inline'
    numberLabelPosition = 'right_align',

    -- format for the number label, by default it displays as for example:  [42]
    numberLabelFormat = '  [%d]',
  },
MagicDuck commented 2 months ago

both Goto Location and Open work with a count now. Need some feedback on the practicality of the thing...

MagicDuck commented 2 months ago

Hmm, it's growing on me after using it a little, haha...

MagicDuck commented 2 months ago

Also added the Open Next and Open Prev actions, bound to <down> and <up> respectively. I like that one better, it's quite smooth:

https://github.com/user-attachments/assets/40aaaf33-f61e-400e-9b60-4fafa04ec284

fabianpage commented 2 months ago

Hey that's very cool! I'm back on the computer on Monday and will try it out!

Thanks for your work!

fabianpage commented 2 months ago

It's very nice, for me the defaults are already great! I would approve the PR ;)

MagicDuck commented 2 months ago

Thanks for the feedback @fabianpage! 😄

Still need to add a bunch of unit tests and I am still not sure I'll make it the default to show those number labels as other people might not use them.

I'll try to get it done and merged when I get some free time.

MagicDuck commented 2 months ago

It's merged now! I left it on by default but reserve the possibility to have it off by default if it annoys enough people 😄