back

Published on

Zsh Keybindings Plugin

Zsh Keybindings Plugin

zsh vim emacs terminal productivity

Have 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:

  1. Vim’s modal editing as the default mode
  2. Emacs-style shortcuts available in insert mode
  3. Visual cursor changes to indicate which mode you’re in
  4. Enhanced menu navigation for completions
  5. 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:

KeybindingAction
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+PPrevious history item
Ctrl+NNext history item
Ctrl+BMove backward one character
Ctrl+FMove forward one character
Ctrl+KKill text to end of line
Ctrl+UKill 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 ManagerInstallation Method
Zap (Recommended)plug "sadiksaifi/zsh-keybindings"
Zinitzinit light sadiksaifi/zsh-keybindings"
Oh-My-ZshAdd 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 quotes
  • i", a": Inner/around double quotes
  • i(, a(: Inner/around parentheses
  • And many more…

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:

  1. The modal editing experience feels native and responsive
  2. Emacs shortcuts work without conflicts in insert mode
  3. Visual feedback helps you always know which mode you’re in
  4. 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:

  1. Use Vim’s normal mode for navigation and complex edits
  2. Drop into insert mode and use Emacs shortcuts for quick line edits
  3. Use Ctrl+A, type something, then Ctrl+E to add to both ends of a line
  4. Move through command history with Ctrl+P and Ctrl+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!