folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.47k stars 33 forks source link

feature: Confirm `/` search with enter #256

Closed fredizzimo closed 11 months ago

fredizzimo commented 11 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

When searching for a non-existing text with / where the start of the pattern matches but the remaining doesn't it's easy to accidentally jump to the wrong location and even make edits by mistake. This happens when the next character you are attempting to match, is also one of the chosen labels.

This is the only thing preventing me from replacing the default(incremental) search with the one from flash.

Describe the solution you'd like

The solution is simple, always require a confirmation by pressing enter.

The first item is displayed without a label, and automatically selected and confirmed by pressing just enter. To select the other items you can press the label, which should not automatically confirm, instead it should just jump to that label, and highlighting the match. Exactly like <CTRL>g and <CTRL>t but with the possibly of skipping matches. When you now press enter that item is confirmed, just like it would in a regular incremental search. ESC always aborts the search, again just like the default behaviour.

I have been running with something that works almost correctly, with this simple change https://github.com/folke/flash.nvim/compare/main...fredizzimo:flash.nvim:confirm-enter. But it's nowhere perfect, the highlighting does not match, and the search pattern shows garbage and so on. But still, this has been my default behaviour for a few weeks now and functionality-wise, I'm very happy with it.

Describe alternatives you've considered

I have tried the trigger character as recommended here https://github.com/folke/flash.nvim/issues/29, but I don't really like it, since you have to press the trigger before the labels appears and even and it also generally works backwards. While my proposal allows you to use the search like before, and optionally use the labels, so there's no new muscle memory involved at all.

Additional context

No response

max397574 commented 11 months ago

https://github.com/folke/flash.nvim/issues/254

fredizzimo commented 11 months ago

That's not the same, I want the labels to always display, but only commit to the final jump with enter.

My enter is on the thumb, so that's as fast as just typing the label, and there's no false positives.

folke commented 11 months ago

just disable search mode and then press <C-S> to show labels when you want or just an explicit keymap to start flash.

There's already multiple ways to handle this. I'm not planning to add yet a new thing for this.

fredizzimo commented 11 months ago

Guess, I will have to do this myself then, because always showing the labels is a huge improvement to the flow. Pressing <C-S> adds an additional reaction time before seeing the labels and typing it, and it also destroys the flow.

Furthermore, there's nothing is my proposal that requires me to create a new type of muscle memory. I can search like normal and only press the label to not have to press <CTRL>g a zillion times. The search is always committed by enter or aborted with esc like it always been. This makes it much more likely that I actually remember to use the labels when I need them.

Syphdias commented 11 months ago

I believe this would be lazy.nvim config to disable flash for search by default while still allowing to activate it with <c-s>.

return {
  "folke/flash.nvim",
  opts = {
    modes = {
      search = {
        enabled = false,
      },
    },
  },
  keys = {
    {
      "<c-s>",
      mode = { "c" },
      function()
        require("flash").toggle()
      end,
      desc = "Toggle Flash Search",
    },
  },
}

PS: Old version was missing the the surrounding opts table.

folke commented 11 months ago

config should be opts

Syphdias commented 11 months ago

Hm, pretty sure I tried opts first since I ran into this a few days ago. I thought it complained about opts. I fixed it now. Thanks!

folke commented 11 months ago

The issue you ran into was that it compained about config being deprectaed and that you need to use opts. Exactly what I said in my comment above.

Syphdias commented 11 months ago

No, because I didn't even try relaunching nvim. I think I mistook a syntax error for something like "has no attribute opts". Just my stupidity, basically :)