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

Switch between search mode on the fly #111

Closed
majutsushi opened this issue Dec 22, 2014 · 12 comments
Closed

Switch between search mode on the fly #111

majutsushi opened this issue Dec 22, 2014 · 12 comments
Labels

Comments

@majutsushi
Copy link

Both the normal fuzzy mode and the two extended modes are very useful for certain cases. However, it is not always clear which mode is the most fitting one for the current search. It would therefore be great if it were possible to switch between the different modes on the fly with a keybinding, and a visual indicator of which mode is currently active. Thanks!

@junegunn
Copy link
Owner

Thanks for the suggestion.

Personally, I exclusively use extended-search mode (FZF_DEFAULT_OPTS="-x") because feature-wise, it's a superset of the other two modes. Often times, I start fzf, type in some characters, and realize I need exact-match to narrow down the candidates. In that case, I can simply prepend ' (quote) to the beginning of the input to turn it into an exact-match term.

  • foobar<CTRL-A>'<CTRL-E> (<ALT-B> and <ALT-F> are also very useful)

Introducing a key to switch modes will save a couple of keystrokes here, but the above method has worked pretty well for me. How about you try it for a while and tell me if you'd still want the switch feature?

@balta2ar
Copy link

I second that request, I also find fuzzy search too broad sometimes. @junegunn Thanks for reminding about exact search using quote, I will give it a try. At the first glance I see weird behavior: I'm using zsh and I see different search results when 1) I press <CTRL-R> and search with exact match 2) when I run history 0 | fzf -x. Though I have added FZF_DEFAULT_OPTS="-x" to my ~/.zshrc.

Is FZF_DEFAULT_OPTS option used when history widget is triggered here?

@junegunn
Copy link
Owner

@balta2ar Yes, did you export the variable? export FZF_DEFAULT_OPTS="-x"

@balta2ar
Copy link

@junegunn oops, my bad! Now it works, thank you! Personally I was thinking about toggling three search modes: exact, regexp and fuzzy. However this extended mode can cover pretty much of my use cases (if not all of them).

This is probably for another issue but I miss <ALT-BACKSPACE> and <ALT-D> shortcuts to delete previous/next word correspondingly. It would be great to support them.

@junegunn
Copy link
Owner

@balta2ar Okay, I'll add those keys and let you know. Is <ALT-BS> equivalent to <CTRL-W>?

@majutsushi
Copy link
Author

I actually though about the quote functionality, but I wasn't sure whether it would be convenient enough if there is more than one search term. But I just had another idea: If you use the "exact" extended mode, the quote character serves no longer any purpose. So would it be possible to reverse its behaviour and make it use fuzzy searching for the "quoted" term? That way the quote essentially becomes a toggle dependent on the base mode.

@junegunn
Copy link
Owner

@majutsushi

but I wasn't sure whether it would be convenient enough if there is more than one search term

Fair enough. But for me navigating between terms hasn't been a problem thanks to <ALT-B> and <ALT-F>, your mileage may vary though. Also, using quotes has the added benefit of allowing me to mix fuzzy terms and exact terms.

So would it be possible to reverse its behaviour and make it use fuzzy searching for the "quoted" term?

It's possible and I thought about it too. But currently in --extended-exact mode, ' can be used to match literal ' characters, so I'm not sure if it's a good call to do so. And as the current documentation describes the mode as follows:

If you don't need fuzzy matching and do not wish to "quote" every word, start fzf with -e or --extended-exact option.

leaving the mode as it is seems to better serve its original intention (and it's simpler). But I'm flexible on this.

@junegunn
Copy link
Owner

@balta2ar Updated!

@balta2ar
Copy link

@junegunn Thank you! Yes, <ALT-BS> and <CTRL-W> are the same.

Two things I noticed, though. <ALT-F> behaviour is inconsistent with one in bash and zsh (readline?). The cursor should go to the first letter of the next word. In your implementation it is stopped at the word separator. <ALT-B> behaviour is correct.

And second, which I don't really know how to make fully compliant, is what to consider a word separator. Say, if you have aaa-bbb=ccc_ddd<CURSOR>, you need to press <ALT-BS> four times (bash, zsh) to delete the whole line while your implementation deletes it in one stroke (this, however, can be tuned in zsh as it has WORDCHARS variable). This is confusing.

@junegunn
Copy link
Owner

@balta2ar Oh yes, I'm aware of the difference but haven't really felt the need to fix it. Perfect readline compatibility would be nice of course, but for fzf, where you never stay more than a few seconds, current implementation suffices. But feel free to create an issue for it, I'll look into it when I get some time.

@junegunn
Copy link
Owner

junegunn commented Apr 3, 2015

Related: #173

@junegunn
Copy link
Owner

I've decided not to do this. Mostly because I haven't felt the need for it so far and it requires non-trivial changes in code, such as cache invalidation, visual indication of the current mode, etc. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants