Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I didn't see Ctrl-r, but I've found that to be the most insanely useful shortcut.

Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it'll find the most recent executed command with that substring in it.

Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.



A complementary tip for Ctr+R is to tag long reusable commands with a comment in the end, e.g.,

find . -name "*.png" -print0 | xargs -0 -P8 pngquant --ext .png --force 256 #optimizepng

(if you’re using zsh, you have to enable INTERACTIVE_COMMENTS option first; just run set -k)


Cool tip, did not know that, though I prefer to put long reusable commands in script files, in part so I can comment them to better remember what everything is doing.


Thanks! I didn't know about INTERACTIVE_COMMENTS.

Adding a comment there is a neat trick. It also works with bang searches (!?), almost like creating a temporary ad-hoc alias:

    find . -name "*.png" -print0 | xargs -0 -P8 pngquant --ext .png --force 256 #optimizepng
    ... many other commands, time passes ...
    !?optimizepng


Since I've switched to zshell, I've found that I haven't used Ctrl-r much at all. The intelligent history feature does it for me. For example:

If earlier I had a long command like `mvn clean test && mvn deploy -P release`, I can just type `mvn v` and press up on the arrows. zsh will present only history entries that start with what I've typed. Insanely useful!


The same thing can be done in bash:

## arrow up

"\e[A":history-search-backward

## arrow down

"\e[B":history-search-forward

(in .inputrc)


I prefer mapping those to page up and page down.


C-s moves forward in history, but you have to type it twice to begin with, once to toggle the mode, and once to actually move forward.

Backspace normally just deletes the last character in your incremental search string.

And be sure that C-s / C-q aren't set up for terminal flow control with something like:

    stty start undef stop undef


Many of the solutions they highlight can actually be solved with this. Surprised that it wasn't included.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: