Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

oh my zsh - How to make zsh keybind between emacs mode and vi mode?

I want to bind a key to toggle emacs mode and vi mode,which I use oh-my-zsh plugins(vi-mode).

I tried Is there a way to switch Bash or zsh from Emacs mode to vi mode with a keystroke?

I also try to bindkey like
bindkey '^[e' 'set -o emacs'
bindkey '^[v' 'set -o vi'

But it's not work for me.

Does any way to toggle vi/emacs or keybind to set keymap?
Thanks a lot !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

bindkey is used for binding keys to ZLE widgets not any random command. So what you have guessed at is not going to work. You could write a custom ZLE widget to switch keymaps:

select-emacs() { set -o emacs }
zle -N select-emacs
bindkey '^[e' select-emacs

In practical terms, I wouldn't recommend this. If you want a hybrid approach, it is better to select emacs mode but bind a key to vi-cmd-mode. In fact Ctrl-X,Ctrl-V is bound to this by default. You might even bind the escape key to vi-cmd-mode - where emacs key sequences involve an initial escape press, that can mostly be replaced by Alt. If you're used to typing it with the actual escape key, you may be able to replace it by a custom widget in vi command mode.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...