0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【zsh】fzf でコマンド履歴を fuzzy 検索

0
Posted at

zsh にはデフォルトで ^R による履歴検索機能がありますが、これを↓のような fzf を使った fuzzy 検索に置き換えてみましょう。

スクリーンショット 2026-07-09 11.57.25.png

手順

~/.zshrc に以下を追記します。

~/.zshrc
# replace ctrl-r with fzf
fzfhistory() {
  local result
  result="$(history -n 1 | fzf --reverse --tac +s --query "$BUFFER")" || return
  BUFFER="$result"
  CURSOR=${#BUFFER}
  zle redisplay
}
zle -N fzfhistory
bindkey '^R' fzfhistory

完成!

使い方

  • $ <^R> で履歴検索の fzf を展開
  • $ <^R> foo <Enter> として、 foo でヒットしたコマンドをコマンドラインに展開
  • $ foo <^R> とすれば最初から foo が fzf のクエリに挿入される
  • $ foo <^R> <^C> として途中で fzf を中止してもコマンドラインに foo が残る
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?