helix
helix copied to clipboard
Make * also select the word under the cursor
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.
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.
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.
This is really necessary!
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
.
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"]
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.
Looks like this is being tackled in #6046