Unable to forward search Bash history similarly as with CTRL-r

前端 未结 5 556
死守一世寂寞
死守一世寂寞 2020-11-30 15:55

I am trying to search my bash history similarly as with CTRL-r, but to forward direction.

It has been a pain for me, when I just hit once too o

相关标签:
5条回答
  • 2020-11-30 16:34

    You may want to try https://github.com/dvorka/hstr which allows for "suggest box style" filtering of Bash history with (optional) metrics based ordering i.e. it is much more efficient and faster in both forward and backward directions:

    enter image description here

    It can be easily bound to Ctrl-r and/or Ctrl-s

    0 讨论(0)
  • 2020-11-30 16:39

    You can search forward as well. From the bash info manual, "8.2.5 Searching for Commands in the History":

    To search backward in the history for a particular string, type C-r. Typing C-s searches forward through the history.

    The problem with Ctrl-S however is that sometimes collides with XON/XOFF flow control (in Konsole for instance). The searching is a readline feature however, and you should be able to bind it to some other key. Update: Simpler and better is just to disable XON/XOFF by running

    stty -ixon
    
    0 讨论(0)
  • 2020-11-30 16:43

    The best trick IMHO is enabling with pgup and pgdown. just put that in your ~/.inputrc

    "\e[5~": history-search-forward
    "\e[6~": history-search-backward
    

    logout/login, type the first letters and then pgup or pgdown to search throughout history

    ctrl-R search all lines containing words, whereas history-search-forward search lines beginning with words

    0 讨论(0)
  • 2020-11-30 16:43

    I usually press ESC in terminal, and then the >. It resets at least and then you could try click less too often CTRL+R.

    0 讨论(0)
  • 2020-11-30 16:52

    Another solution is to use:

    history | grep <searched expression>

    0 讨论(0)
提交回复
热议问题