Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use both Emacs and Vim keybindings in zsh?

Tags:

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 ?

like image 382
zk_phi Avatar asked Jul 01 '16 09:07

zk_phi


People also ask

Does vim have emacs mode?

Overview. Vim-mode is another implementation for Vi and Vim-like key bindings for Emacs. It is a complete new implementation from scratch with extensibility in mind. There are several other packages emulating Vim features, see CategoryEmulation for an overview.


1 Answers

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.

like image 164
Adaephon Avatar answered Sep 23 '22 09:09

Adaephon