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 autocomplete within one's history and eliminates most of my up
, up
, up
, up
, up
behavior.
From a UX perspective, Ctrl+R
works perfectly for me. It's already part of my muscle memory on a few key commands I run a lot. It works by searching through your recent .bash_history
. Once you see the command you are looking for, you can press return to execute it or use the left and right arrow buttons to modify it. If you are not seeing the command you want, or can't quite remember the params you need, you can keep hitting Ctrl+R
to cycle through the results. It's a very natural flow.
If you're still addicted to up
, up
, up
, up
, up
, I hope you try this command for yourself.
Top comments (34)
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/ !!