Skip to content
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 to word boundary if we are at a single char selection when pressing * #6045

Open
magopian opened this issue Feb 18, 2023 · 4 comments · May be fixed by #6046
Open

Expand to word boundary if we are at a single char selection when pressing * #6045

magopian opened this issue Feb 18, 2023 · 4 comments · May be fixed by #6046
Labels
C-enhancement Category: Improvements

Comments

@magopian
Copy link
Contributor

When pressing * to use the current selection as the search pattern, it would be useful to automatically expand to the whole word if there's a single char being selected.

The logic behind this is:

  • in vim, pressing * automatically searches for the word under the cursor (no need to first select the word)
  • it doesn't seem very useful to search on a single char selection (and if it's needed, one could still press /<the char to search> to achieve the same result)
  • if more than one character is selected, only search for this selection without expanding to the whole word: keep the way it's working actually

This has been discussed on matrix with @pascalkuthe:

I'm working on a PR for this proposition ;)

@magopian magopian added the C-enhancement Category: Improvements label Feb 18, 2023
@magopian magopian linked a pull request Feb 18, 2023 that will close this issue
@archseer
Copy link
Member

You could remap this inside your user config to do miw before *

@the-mikedavis
Copy link
Member

miw would need macro keybinds (#1383) but you can emulate it for the most part with be:

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

I don't want to see this as built-in behavior for *: automatic changes to the selection make it hard to reason about the behavior of these commands especially when you have multiple selections. I think it fights with the select-then-act paradgim.

@pascalkuthe
Copy link
Member

pascalkuthe commented Feb 19, 2023

miw would need macro keybinds (#1383) but you can emulate it for the most part with be:

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

I don't want to see this as built-in behavior for *: automatic changes to the selection make it hard to reason about the behavior of these commands especially when you have multiple selections. I think it fights with the select-then-act paradgim.

The description and issue title are misleading.

I suggested that * could select the entire word on matrix if:

  • there is only a single selection
  • that single selection is only a single word long

I only suggested this because gf already does this and a single char search is comparatively useless.
That is what was implemented in #6046.

I do agree it fights a bit with selection => action paradigm but I taught that the additional usability would be worth it here for the same reasons as in gf (searching for a single char is mostly useless as we have f/t for that)

@MilanVasko
Copy link
Contributor

I'd like to add my 2 cents:

I don't want to see this as built-in behavior for *: automatic changes to the selection make it hard to reason about the behavior of these commands especially when you have multiple selections. I think it fights with the select-then-act paradgim.

I agree completely, it's a surprising behavior and makes the editor unpredictable.

Also it breaks one use case I bump into more often than I'd like - searching for unicode or malformed characters. Say I need to work with a generated SQL file which has a messed up encoding and I want to fix it. It's very practical to be able to select the malformed character, search for it in the whole file and replace it with the correct one. Pressing /<the character> doesn't cut it in this case, because I don't even know how to put that character in the prompt (except copy-pasting, which is very impractical).

I don't mind having the functionality mentioned in this issue, but please make it a separate command so that I can still use the old behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants