helix icon indicating copy to clipboard operation
helix copied to clipboard

Make * also select the word under the cursor

Open antoyo opened this issue 2 years ago • 5 comments

Describe your feature request

I would find it more convenient if * would also select the word under the cursor before doing a search. The search should also be on word boundary (wrapped with \b). That's the behavior of vim.

We can keep the current search_selection as it is, perhaps under another shortcut.

antoyo avatar Mar 06 '22 16:03 antoyo

Now that I think of it, perhaps we only need to have a command for the <C-s> shortcut in the prompt and to submit the search. That would allow use to remap * to the following:

[keys.normal]
"*" = ["search", "insert_word", "submit_search"]

What do you think?

This seems more generic and would allow for instance creating a new shortcut to do the same for global search.

However, we'd need a way to wrap the word with \b. Any idea for how we could do this? I guess we could make a command for this, but that doesn't seem generic to me.

Now that I think of it, that would require many commands while issue #1383 would allow something like:

"*" = "@/\b<C-s>\b<CR>"

which seems much simpler.

That wouldn't work as is, though, because the search is incremental.

antoyo avatar Mar 06 '22 16:03 antoyo

currently * will set register / to current char, which I think is not the most freq case.

it's good to make it default select the word.

ttys3 avatar Apr 21 '22 02:04 ttys3

This is really necessary!

txtyash avatar Sep 28 '22 17:09 txtyash

At the very least I would expect * to actually execute the search. Right now to do what * does in VIM which is a pretty common operation you need to do something like alt+o followed by * and then n.

mitsuhiko avatar Oct 10 '22 14:10 mitsuhiko

I ended up with this binding BTW that mostly emulates what I'm currently used to from vim:

[keys.normal]
"*" = ["move_prev_word_start", "move_next_word_end", "search_selection", "search_next"]

mitsuhiko avatar Oct 11 '22 11:10 mitsuhiko

For the record, # and * in vim (respectively backward and forward search of symbol under the cursor) is incredibly useful to read code as it helps tracking usages of a given symbol. Here is a demo of a typical symbol tracking workflow in nvim using # and *:

https://user-images.githubusercontent.com/34467/218343565-646523d4-2fe4-4416-8523-f60fae98356b.mp4

I'm guessing https://github.com/helix-editor/helix/pull/5702 will also help here.

ubitux avatar Feb 12 '23 23:02 ubitux

Looks like this is being tackled in #6046

milesfrain avatar Apr 18 '23 04:04 milesfrain