3
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?

More than 3 years have passed since last update.

zshのスニペット&補完プラグイン zeno.zsh と略語展開プラグイン zsh-abbrev-alias を共存させる

Last updated at Posted at 2022-05-22

yuki-yano/zeno.zsh はあらかじめ登録したスニペットの展開をしてくれるzshプラグイン。
例えば gsgit status に登録すると、gs<SPACE>git status に展開してくれる。
あと、コマンドラインが特定のパターンにマッチすると fzf を使った補完モードに入ってくれる。
これの詳しい魅力については 作者の記事この人の記事 を見るといいだろう。

しかし略語展開プラグイン mono-lab/zsh-abbrev-alias紹介記事) と競合する。
abbrev-alias は勝手にスペースキーとエンターキーにバインドして、これが zeno.zsh と競合するのだ。

スペースキーとエンターキーの取り合いを解消するために以下の設定をした。
zinit プラグインマネージャーの機能を使っている。

# zeno.zsh のインストール設定
zinit ice lucid depth"1" blockf
zinit light yuki-yano/zeno.zsh

# zsh-abbrev-alias のインストール設定
# 遅延読み込みにして zeno.zsh より後に読み込ませる。
# atload プレフィクスで読込終了時に ___abbrev-alias--loaded 関数を呼びだす
zinit ice wait'!0' lucid atload'___abbrev-alias--loaded'
zinit load "momo-lab/zsh-abbrev-alias"

# この関数内でスペースとエンターに2つのプラグインを合成させたアクションを割り当てさせる
# この関数は zsh-abbrev-alias ロード後に呼ばれる。
function ___abbrev-alias--loaded(){
  _mixed-space(){
    zle __abbrev_alias::magic_abbrev_expand
    zle zeno-auto-snippet
  }
  zle -N mixed-space _mixed-space
  bindkey ' '  mixed-space

  _mixed-enter(){
    zle __abbrev_alias::magic_abbrev_expand
    zle zeno-auto-snippet-and-accept-line
  }
  zle -N mixed-enter _mixed-enter
  bindkey '^m'  mixed-enter
}

初めに abbrev_alias が起動して略語展開を行ったのち、zeno が起動するようにした。

zeno.zsh と zsh-abbrev-alias を併用できて何がうれしいのか(zeno.zshだけで充分でないか?)についての回答

  • zsh-abbrev-alias で登録した略字展開は zeno-insert-snippet (fzf でスニペットを検索する)の候補に登場させずに済む
  • HIST_IGNORE_SPACE オプション(行頭空白)に2022年5月24日現在、zsh-abbrev-alias は対応している(zeno.zsh は未対応)
3
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
3
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?