zk_phi
zk_phi

Reputation: 195

Can I use both Emacs and Vim keybindings in zsh?

I use zsh and I've recently learned bindkey -v binds useful Vim keybinds at once, but I also realized that, when I use bindkey -v, all default (Emacs-like) keybinds are disabled.

I want to use Emacs-like keybinds when I'm in the insert-mode, while Vim keybinds are also enabled when I'm in the normal-mode.

Can I use both Emacs and Vim keybinds in zsh ? And if yes, how can I do ?

Upvotes: 8

Views: 2327

Answers (1)

Adaephon
Adaephon

Reputation: 18399

Yes, you can. It is even part of the default bindings.

To get emacs-like bindings for "insert-mode", you simply set emacs as default keymap. This is already the case, unless either of the VISUAL or EDITOR environment variables contain the string vi and unless you set it to viins explicitly with bindkey -v. You can also set it explicitly with bindkey -e.

From emacs mode you can then switch to vicmd mode ("normal-mode") with the key sequence ^X^V, that is Ctrl+x followed by Ctrl+v. To get back to emacs mode just type any key sequence that would normally get you to viins mode ("insert-mode") with vi-like bindings, e.g. i or a.

Upvotes: 8

Related Questions