64

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?

2
  • 1
    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, 2015 at 8:44
  • 10
    @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. Aug 7, 2016 at 19:34

10 Answers 10

71

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.

0
11

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.

11

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

this library provide powerful search for fish shell.

2
  • fzf is a great utility but how would you use it to search the fish history and execute commands from there? Oct 29, 2023 at 23:13
  • Never mind, Duke explains it in his answer - the "magic" is provided by the fzf fish plugin that allows to use fzf to search and execute commands from the fish history. Oct 30, 2023 at 1:21
6

Now in fish shell 3.6.0

https://github.com/fish-shell/fish-shell/releases/tag/3.6.0

By default, Control-R now opens the command history in the pager (#602). This is fully searchable and syntax-highlighted, as an alternative to the incremental search seen in other shells. The new special input function history-pager has been added for custom bindings.

1
  • Amazing! Thanks for sharing.
    – Hyomin Kim
    Jul 2, 2023 at 15:24
5

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
3

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

2

For whom still struggling find something like Ctrl + R, I use Ctrl + P instead.
This is powerful same as reverse searching (Ctrl + R).

You can use like below:

  1. Type some partial keyword you want to find

  2. And then, press Ctrl + P

  3. Repeat press P until the command appears.

1
  • 2
    That's probably the same what the Up key does (works the same, just instead of Ctrl + P, press just Up). Oct 30, 2023 at 1:24
1

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]

1

instead of ctrl + R you can use ctrl + shift + tab just after you type the first part you wanted to search:enter image description here

1
  • Isn't it exactly what just the Tab key alone does? The Ctrl + Shift + Tab usually switches tabs in terminal apps anyway. Oct 30, 2023 at 1:27
0

You can use peco in FISHELL as your reverse-i-serach. You have to make abbreviations in your config.fish file in /home/user/.config/fish/ Directory

I am using abbr rr "history | peco" and then if i type rr -> enter im in history-search. But i have problem right now.. If I search for string in history and type enter it does not do anything :/

EDIT: Okay I was searching web for the solution of executable peco history and i found this website - https://jonasweissensel.de/post/fish_peco/

Just follow the directions and put it into your config.fish file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .