2
1

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 5 years have passed since last update.

zshでその場でbindkey -v(あるいは bindkey -e)する

Posted at

zsh で普段は bindkey -e だけど突発的にここで20文字右に行きたくなって bindkey -v だったら20lしてるのになあという貴方向けのキーバインド

bindkey-e-inline() {
  zle vi-insert
  local pos
  pos=$CURSOR
  zle push-line
  bindkey -e
  zle get-line
  CURSOR=$pos
}

bindkey-v-inline() {
  local pos
  pos=$CURSOR
  zle push-line
  bindkey -v
  zle get-line
  zle vi-cmd-mode
  CURSOR=$pos
}

zle -N bindkey-e-inline
bindkey -M viins "^e" bindkey-e-inline
bindkey -M vicmd "^e" bindkey-e-inline
zle -N bindkey-v-inline
bindkey "^xv" bindkey-v-inline

bindkey -e の状態で C-x v でカーソル位置そのままで bindkey -v を、 vi モードでは C-e で同様に bindkey -e を発行する。
(実際のキーは適当に変更しましょう)

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?