
Zsh Keybindings Plugin
zsh vim emacs terminal productivityHave you ever found yourself torn between the modal efficiency of Vim and the familiar shortcuts of Emacs in your terminal? If so, you’re not alone. Many developers and terminal power users eventually settle on one or the other, but what if you could have the best of both worlds?
The Best of Vim and Emacs in Your Terminal
The Dilemma: Vim vs. Emacs Keybindings
Vim users love the modal editing approach that lets them navigate and manipulate text with minimal keystrokes. The ability to use hjkl
for movement and combinations like ciw
(change inside word) make text editing incredibly efficient once you’ve built the muscle memory.
Emacs enthusiasts, on the other hand, appreciate the consistent control-key combinations that work across different applications. Commands like Ctrl+A
to jump to the beginning of a line or Ctrl+K
to kill text to the end of line become second nature.
Enter the Zsh Keybindings Plugin
I created this plugin to solve my own frustration with having to choose between these two paradigms. The result is a seamless integration that gives you:
- Vim’s modal editing as the default mode
- Emacs-style shortcuts available in insert mode
- Visual cursor changes to indicate which mode you’re in
- Enhanced menu navigation for completions
- Advanced text objects for working with quotes and brackets
How It Works
The plugin sets Vim keybindings as the default, giving you the classic normal and insert modes with visual feedback:
- Insert mode shows a beam cursor (
|
) - Command mode displays a block cursor (
█
)
But the magic happens when you’re in insert mode. All the familiar Emacs shortcuts are available:
Keybinding | Action |
---|---|
Ctrl+A | Move to beginning of line |
Ctrl+E | Move to end of line |
Ctrl+P | Previous history item |
Ctrl+N | Next history item |
Ctrl+B | Move backward one character |
Ctrl+F | Move forward one character |
Ctrl+K | Kill text to end of line |
Ctrl+U | Kill text to beginning of line |
You get the best of both paradigms without compromise.
Installation
Getting started with the plugin is easy. Choose your preferred Zsh plugin manager:
Plugin Manager | Installation Method |
---|---|
Zap (Recommended) | plug "sadiksaifi/zsh-keybindings" |
Zinit | zinit light sadiksaifi/zsh-keybindings" |
Oh-My-Zsh | Add to plugins array after cloning to custom plugins |
Advanced Features
Vim Text Objects
For Vim power users, the plugin supports text objects for quotes and brackets:
i'
,a'
: Inner/around single quotesi"
,a"
: Inner/around double quotesi(
,a(
: Inner/around parentheses- And many more…
Menu Completion Navigation
Tab completion in Zsh becomes more powerful with Vim-style navigation:
- `Ctrl+J`: Move down in completion menu
- `Ctrl+K`: Move up in completion menu
- `Ctrl+H`: Move left in completion menu
- `Ctrl+L`: Move right in completion menu
Why This Plugin?
There are several Vim mode plugins for Zsh, and the shell itself supports Emacs bindings out of the box. However, most solutions force you to choose one or the other, or implement a clunky experience when trying to combine them.
This plugin was carefully designed to ensure that:
- The modal editing experience feels native and responsive
- Emacs shortcuts work without conflicts in insert mode
- Visual feedback helps you always know which mode you’re in
- Common terminal navigation patterns aren’t broken
Real-world Usage
I’ve been using this setup for my daily development work for months, and the productivity boost is substantial. Common patterns become incredibly efficient:
- Use Vim’s normal mode for navigation and complex edits
- Drop into insert mode and use Emacs shortcuts for quick line edits
- Use
Ctrl+A
, type something, thenCtrl+E
to add to both ends of a line - Move through command history with
Ctrl+P
andCtrl+N
while in insert mode
Conclusion
The Zsh Keybindings plugin represents the best of both worlds for terminal users. Whether you’re a Vim devotee who occasionally wants Emacs shortcuts, or an Emacs user who wants to experiment with modal editing, this plugin provides a seamless experience.
Give it a try with:
# Using Zap plugin manager
plug "sadiksaifi/zsh-keybindings"
The source code is available on GitHub, and contributions are welcome! Check out the CONTRIBUTING.md file for guidelines on how to help improve the plugin.
What keyboard shortcuts do you find most essential in your terminal workflow? Let me know in the comments!