Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Agreed, but even nicer than control-r are the readline functions `history-search-backward` and `history-search-forward`.

Personally I bind them to up/down which on OS X at least involves:

  # Put this in some file like ~/.readline-bindings
  "\e[A": history-search-backward
  "\e[B": history-search-forward

  # And this in your ~/.bashrc or ~/.zshrc
  bind -f ~/.readline-bindings
That way if you haven't typed any input it behaves like normal up (previous command), but if you've typed some characters it only retrieves matching commands.

http://codeinthehole.com/writing/the-most-important-command-...



view as:

Mapping these to Up/Down arrows (instead of PgUp-PdDn) is the best idea EVER !!!

Just curious since I don't use a mac, doesn't writing the mappings to .inputrc work? IIRC, putting your readline bindings there makes it available for all readline enabled prompts, not just bash ie: Python, pgsql, mysql,.. Etc

Yes I think that's a better approach, thanks. I don't know why I started using `bind` in my shell config.

Is there a way to make this work with `set -o vi`? So I can use j/k to browse the history this way?

Legal | privacy