-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand selection to whole word when pressing *
#6046
base: master
Are you sure you want to change the base?
Expand selection to whole word when pressing *
#6046
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change and the implementation looks reasonable to me too as its just lifted from goto_file
👍
Searching for a single char with *
seems like a nieche use-case: *n
it not much shorter than /[char]<ret>
or f[char]
.
Automatically using the word under the cursor is consistent with gf
and can be super useful.
However this behavior change should be documented in keymap.md
.
Currently it says:
Use current selection as the search pattern
Wit this PR something like the following would help:
Use current selection as the search pattern, if only a single char is selected the current word (
miW
) is used instead
Thanks for the feedback, I've updated the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now 👍
nice improvement. going to test it locally. currently was using this config:
|
I think it makes sense to encapsulate the word between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially opposed to this behavior (along these lines: #6045 (comment)) but with the special registers from #6985 you can search for the current selection exactly with /<C-r>.
. So I think this would be a nice improvement. I left a few small comments and pushed up a merge with master since there were some changes from the special registers PR that conflicted
primary, | ||
textobject::TextObject::Inside, | ||
count, | ||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing false
here makes this look for the surrounding "word" rather than the "WORD". I think that's an ok behavior but the change in book/src/keymap.md
should mention miw
instead of miW
. Also see
helix/helix-term/src/commands.rs
Lines 5000 to 5001 in d570c29
'w' => textobject::textobject_word(text, range, objtype, count, false), | |
'W' => textobject::textobject_word(text, range, objtype, count, true), |
Some("ifoobar::baz<ret>bar::crux<esc>k3blC*"), // k3b places the cursor on the first letter of 'foobar', then move one to the right for good measure, then adds a cursor on the line below | ||
Some(&|app| { | ||
assert!( | ||
// The selections don't seem to be ordered, so we have to test for the two possible orders. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe what's happening here is that collecting into a hashmap might change the order. The selections do have a deterministic order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source code could add the itertools
crate and then use unique
on the iterator instead of collecting twice. unique
is stable.
I believe Kakoune also adds |
If there's anything that needs to be done to merge this, I'm happy to help! |
Closes #6045
This is an attempt at adding the functionality discussed in this issue (and earlier on matrix).
I'm open to suggestions, I've barely learned Rust, and it was a long time ago and seldom used it, so i'm very... rusty.
Please let me know if this is useful, relevant, and how it could be improved!