36

I’m really impressed with Fish’s autocomplete functionality. However there is one feature in Bash that I’m unable to find in Fish. When you press Ctrl+R in Bash and begin to type out a term, a search is done on your .bash_history to find matches in reverse order.

Is there a similar functionality in Fish?

  • The thing to note about fish's up/down arrow feature is that it is far less powerful than bash's reverse-search. This becomes obvious when you can remember your argument, or an option, but not from the first part of your command. Reverse search does a fuzzy inline search, fish just checks for identical start of sentence. – Kasper HJ Jun 4 '15 at 8:44
  • 6
    @KasperHJ, I think your comment may be out of date. I typed sta and pressed up, and it found git stash list. I just started using Fish recently, so I don't know if this is a recently-added feature or something that has been in Fish for a long time. – Elias Zamaria Aug 7 '16 at 19:34
45

I've never used fish myself but a cursory google search brought up this page which states that

Powerful History Mechanism

Modern shells save previous commands in a command history. You can view earlier commands by using the up and down arrows. Fish extends this concept by integrating the history search functionality. To search the history, simply type in the search string, and press the up arrow. By using the up and down arrow, you can search for older and newer matches. The fish history automatically removes duplicate matches and the matching substring is highlighted. These features make searching and reusing previous commands much faster.

Is that what you are looking for? It seems quite similar to bash's.

7

fish doesn't implement incremental history search, although it seems to come up fromtime to time. The pre-2.0 documentation has a "Missing features and bugs" section 1 which lists incremental history search fairly far down in the "Possible features" list. The fish-users mailing list includes this message from Axel Liljencratz, dated August 21, 2006, in which he says that incremental search would be a nice feature to have.

If you're used to bash-style incremental search, fish history searching does take a bit of getting used to. You have to type the search term first, and you move up and down matching entries with up- and down- arrow. But I suppose you get used to it.

5

You can use : https://github.com/junegunn/fzf

this library provide powerful search for fish shell.

2

There is a feature request opened in the fish bug tracker:

https://github.com/fish-shell/fish-shell/issues/602

Someone already implemented a workaround for this:

https://github.com/jbonjean/re-search

1

Far better Ctrl+r reverse searches with FZF and fzf fish plugin, using the Triton fish package manager, configured to use The Silver Searcher.

~/.config/fish/config.fish:

triton jethrokuan/fzf
set -U FZF_COMPLETE 2
set -U FZF_FIND_FILE_COMMAND "ag -l --hidden --ignore .git"
set -U FZF_DEFAULT_OPTS "--height 40% --layout=reverse --border"

On Mac OS, to install the prereqs:

brew install the_silver_searcher
brew install fzf
0

Using up and down arrows it's not a good alternative to Ctrl+R, because if the phrase you are looking for it is really deep in the history, you'll have to hit up/down keys a lot! I just use history | grep -i [phrase]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.