I only recently started integrating Ctrl+R into my command-line workflow, and I am happy I did! The command, called reverse-i-search, starts an aut...
For further actions, you may consider blocking this person and/or reporting abuse
This is surely a life saver for me. Just tried it. And it works!!!! :)
For me, what's even better than Ctrl-R is the Fish shell. In Fish, you type something that you want to search for in your history and then press up, and it goes back through your history and only shows commands that match what you typed. Your shell configuration looks pretty bare-bones from the screenshot, so you might also appreciate the syntax highlighting and very high-quality autocomplete.
The website is at fishshell.com. If you have Homebrew, you can install it with
brew install fish
.yup. I've been using Fish since I started programming and I fail to see why it's not omnipresent. One you go fish you never go back.
It's same for zsh with
ohmyzsh
, just write the start andup
up
:)The thing I don't like about zsh is you need a whole pile of custom code such as ohmyzsh and its plugins, which really slow it down. All the cool things about fish are built in, and written in C++.
I've never used fish, so I think I will give it a try!
And who says zsh's plugins slows its functionality down? It even works better and faster with its plugins + OhMyZsh.
Thanks for the tip. I'll look into it. If you're interested in breaking this out into your own post with an intro + tips on fish, and why you use it, I think that would be useful for folks.
This is also in Bash, but requires a little bit of config. Put this into your
~/.inputrc
file:This emulates the functionality of Oh My Zsh, where if you type a letter or word, then press up or down, it will search through the
.bash_history
file.The only thing I miss from Oh My Zsh is a "visual selector" for files, by tabbing through a virtual list, and ignoring cases when tabbing to a folder.
I'm also a heavy fish user. Perhaps we should write something for fish and zsh?
Do it!
Tried almost every shell out there and I can say Fish is just the best
See also Hashtags for commands, wherein you add a
#somethingmemorable
after a complicated command, making it easier to Ctrl+R for it in future.fzf is even more amazing than the plain ctrl+r - github.com/junegunn/fzf
Hands down one of the first things I install on a new computer
I have come to enjoy: McFly
REF: github.com/cantino/mcfly
If I want to use the last
scp
command, I simply use!sc
for example.And I use my lazy bash alias for grepping my history (
h grep
)Nice 👌
Take a look at:
hstr (history suggest box): github.com/dvorka/hstr - it's way better than standard reverse-i-search
Even much better is ZSH's history-substring-search plugin: asciinema.org/a/89727
I'm a big fan of
Ctrl+r
, but sometimes eschew it for the limited duplicateup
s afforded byexport HISTCONTROL=erasedups
HISTIGNORE is also a good tool
REF: jonasbn.github.io/til/bash/slimmin...
Great article! Ctrl -R is great!
I set up my command line to use vim like keybindings. You have to run this command first, or put it in your .zshrc or .bashrc.
set -o vi
To search I press the escape key then /. I can also go to the end of the command line by pressing ^, or the front by pressing $. I can delete words just like I'm in vim.
Another awesome thing to do is set some key mappings to your terminal (I use the magnificent iTerm) to better navigate through the words in your lines.
Like alt-left to go back a word, or cmd-Del to delete the whole line, or alt-Del to delete just a word, etc.
My most used key mappings (OSX):
Cmd + Left Arrow : Send Hex Codes
0x01
(Start Of Line)Cmd + Right Arrow : Send Hex Codes
0x05
(End Of Line)Option + Left Arrow : Send Escape Sequence
b
(Go Back a Word)Option + Right Arrow : Send Escape Sequence
f
(Forward a Word)Cmd + Del : Send Hex Codes
0x15
(Delete Line)aren't many of these mapping are built into bash by default?
ctrl-a : beginning of line
ctrl-e : end of line
ctrl-w : delete last word
ctrl-k : cut to end of line
ctrl-y : paste cut item
meta/alt/command-f: move forward a word
meta/alt/command-d: cut forward a word
...?
and on OSX/macOS, some of these mappings are system wide:
redgreenrepeat.com/2016/10/14/extr...
try ohmyz.sh/ !!
This is totally tangential, but what did you use to capture the animated gif?
Waouw didn't know about that! Thx Ben!
I loved it _
It never ceases to amaze me that I find something like this after years of using bash. Thanks for the tip!
Do Try McFly
REF: github.com/cantino/mcfly
Another upside is that this works with all applications that use libreadline. I just used this to bring up a complex SQL query from my ~/.mysql_history, and it also does the job for Python 3.x.
In zsh, I bound ctrl-R to history-incremental-pattern-search-backward, which allow wild cards in the search string. It's even more useful.
This is what I use, really enjoy it. Still "autocompletes", but you don't have to move from the arrow keys
Thats awesome! Going to use that. Ohmyzsh does some interesting things too, but definitely my pattern is still a few too many up arrow keys :)