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のEsc-pを直感的な挙動に変更する

Last updated at Posted at 2025-04-05

zshのEmacsモード(bindkey -e)でEsc-pを入力すると、最初のワードをキーにしてコマンド履歴を検索します。この時、第二ワード以降は無視されます。

例えば、

1. git commit -a
2. vi file.txt
3. git diff

とコマンドを実行したあとに、git cまで入力してEsc-pを押すと、3が選ばれます。元tcshユーザーとしては1にマッチしてほしいし、この挙動の方が自然だと思う。

Esc-pに割り当てられているup-line-or-searchをzshcontribに含まれているup-line-or-beginning-searchに変更することでこの問題を解決できます。

Esc-nに対しても同様の修正を適用します。

autoload -U up-line-or-beginning-search
zle -N up-line-or-beginning-search
bindkey "^[p" up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[n" down-line-or-beginning-search

zshはなんでこんな不可解な挙動がデフォルトなんだ。

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?