3 minute read

Emacs and Vim: Best Practices for Finding Your Ideal Workflow

Over the years, I’ve explored both Vim and Emacs, experimenting with various configurations and workflows. While many programmers find great joy in Vim’s modal editing, I’ve come to realize that Emacs’ native shortcuts and workflows suit me far better. Despite giving Vim a fair shot, I’ve found that sticking to Emacs keybindings allows me to work more fluidly. Here’s a breakdown of my experiences and some tips for choosing the approach that works best for you.

Exploring Vim/Evil Commands

Vim Keybindings I Tried

  • Deleting and Changing Words:

    • daw : Deletes the word under the cursor.
    • caw : Deletes the word under the cursor and switches to insert mode.
    • ciw : Changes the entire word under the cursor.
    • cw : Changes the word from the current cursor position.
  • Navigating Lines:

    • Typing the line number followed by G to jump directly to a line (e.g., 30G).
  • Indentation and Context-Specific Deletions:

    • dii : Deletes all content within the current indentation scope.
  • Commenting and Uncommenting Lines:

    • gcc : Toggles comments on the current line.

Why Vim Keybindings Didn’t Work for Me

While I appreciated the speed and precision of Vim’s modal editing, I often found myself stumbling over the need to switch between modes. My muscle memory strongly favors the flow of Emacs’ commands, which felt more natural for my style of work. For example, I prefer using C-g to escape actions and sticking to the home row for navigation.

Advantages of Sticking with Emacs Keybindings

For programmers like me, Emacs keybindings offer:

  • A consistent workflow that minimizes mode switching.
  • Easy access to commands without extensive remapping.
  • Integration with powerful tools like Org-mode and Magit.

Emacs Counterparts to Vim Commands

Here are the Emacs equivalents for some common Vim commands:

  • Deleting and Changing Words:

    • M-d : Deletes the word after the cursor.
    • C-Backspace : Deletes the word before the cursor.
    • M-t : Transposes words.
    • M-% : Initiates a search-and-replace for the word under the cursor.
  • Navigating Lines:

    • M-g g : Jumps directly to a specific line (e.g., M-g g 30 to go to line 30).
  • Indentation and Context-Specific Deletions:

    • C-M-\ : Reindents the current region.
    • C-Space followed by navigation, then C-w : Deletes a region based on indentation.
  • Commenting and Uncommenting Lines:

    • M-; : Toggles comments on the current line or region.

But What About Evil Mode?

Evil mode—Emacs’ vi layer—is an excellent choice for those who love Vim but want to leverage Emacs’ extensibility. It brings Vim’s efficiency to Emacs, allowing users to:

  • Navigate and edit text with Vim commands.
  • Use advanced features like visual navigation (gs/, gsj, gsk) or jumping across buffers (gss).
  • Discover hidden Evil bindings (SPC h b t) and redefine escape sequences (jk or C-g).

For those who naturally align with Vim’s editing philosophy, Evil mode can be transformative.

The Role of Doom Emacs

Doom Emacs has played a pivotal role in bridging the gap between Vim and Emacs users. As a modern Emacs distribution, it offers:

  • Preconfigured Evil Mode: Doom Emacs integrates Evil mode seamlessly, making it easy for Vim users to transition to Emacs without sacrificing their preferred editing style.
  • Modular Configuration: Doom’s modular approach allows users to enable only the features they need, reducing bloat and improving performance.
  • Streamlined Keybindings: It introduces a consistent and logical set of keybindings, combining the best practices of both Vim and Emacs.
  • Enhanced UX: With polished themes, a snappy startup time, and optimized defaults, Doom Emacs provides a user-friendly experience that appeals to beginners and advanced users alike.

By catering to both Vim enthusiasts and Emacs purists, Doom Emacs demonstrates that the two worlds can coexist harmoniously. It’s a fantastic starting point for anyone looking to explore the best of both editors.

Finding Your Editing Style

Every programmer’s workflow is unique. Some thrive with Vim’s modal editing, while others prefer the uninterrupted flow of Emacs keybindings. Here’s how to decide:

  1. Experiment: Spend dedicated time with both styles.
  2. Evaluate Your Comfort Level: Consider which workflow feels more intuitive and natural for long coding sessions.
  3. Customize: Both Vim and Emacs are infinitely customizable. Find shortcuts and extensions that enhance your productivity.

Conclusion

While Vim’s efficiency is undeniable, Emacs’ native keybindings have proven to be my ideal choice. That said, each programmer can discover their own path—whether that means sticking with Vim, embracing Emacs, or combining the two through Evil mode. Ultimately, the best tool is the one that helps you code with confidence and joy.

Happy exploring!

Updated:

Have comments or want to discuss this topic?

Send an email to ~bounga/public-inbox@lists.sr.ht