Vim vs Emacs

James MathengeJames Mathenge
11 min read

Introduction

Text editors are one of the most fundamental tools used by programmers and power users. Choosing the right editor can have a significant impact on productivity. Two of the most popular and powerful command-line text editors are Vim and Emacs. Both have been around since the 1970s and offer extensive customizability. However, vim and emacs represent very different approaches to text editing.

Vim (short for Vi IMproved) is an evolution of the vi editor created by Bill Joy in 1976. It emphasizes keyboard shortcuts and modes to enable efficient text editing. Emacs (originally standing for Editor MACroS) was created by Richard Stallman in 1976 as a set of custom macros for the TECO editor. It utilizes key chords and emphasizes being fully programmable and customizable.

Both Vim and Emacs are rich in features and have extensive plugin ecosystems thanks to their scripting languages Vimscript and Emacs Lisp respectively. Choosing between them often spurs heated debate amongst programmers. This comprehensive article will dive into the history, design philosophies, features, and usage differences between Vim and Emacs across various categories. The goal is to provide readers with a deep understanding of how the two editors compare, so users can decide which one aligns better with their needs and preferences.

While Vim and emacs share similarities, such as being keyboard-driven command line editors, they represent divergent approaches to text editing with fundamental differences in their interface, customizability, and overall philosophy. This article will illuminate these distinctions to help readers appreciate the strengths and weaknesses of each editor. With informed knowledge, users can determine which editor best suits their editing style and workflow.

History and Origins

The stories of Vim and Emacs begin in the 1970s during the early days of Unix. At the University of California Berkeley in 1976, a computer science graduate student named Bill Joy created an editor called vi (short for visual) for an early version of Unix. vi was built upon the ed line editor and intended to be a more user-friendly improvement. Joy carefully designed vi around efficient text editing through different modes and keyboard shortcuts.

That same year at the MIT AI Lab, a young programmer named Richard Stallman began work on Emacs, which stood for Editor MACroS. Frustrated by the limitations of the TECO editor, Stallman set out to create a fully customizable and programmable editor by writing macros to extend TECO's functionality. This "infinitely extensible" design philosophy became core to the DNA of Emacs.

Over the next few decades, Vi and Emacs evolved and spread rapidly throughout the burgeoning Unix world, establishing ardent followings. In the late 1980s, vi clones such as Vim emerged, adding additional features like multi-level undo. Vim keybindings became a required skill for Unix system administrators. On the Emacs side, Richard Stallman's newly formed Free Software Foundation released GNU Emacs in 1984. GNU Emacs became the standard bearer for the open-source movement and introduced cross-platform support beyond Unix.

The heated but good-natured rivalry between vi/vim and Emacs users has fueled countless tech debates. Both editors have proven their longevity and remain extremely popular today, inspiring scores of plugins, extensions, and derivatives. Their distinct approaches to text editing continue to shape how programmers optimize their workflow.

Philosophy and Design

Vim and Emacs were conceived with different design philosophies that extend to the core of how they operate.

Vim draws heavily from the modal philosophy of its predecessor vi. It has distinct modes for inserting text (Insert mode) versus manipulating text (Normal mode), which sets it apart from most editors. Vim is optimized for efficiency and avoiding excessive keystrokes or using the mouse. Keyboard shortcuts in Normal mode allow quick navigation and edits. For example, dd deletes a whole line. Vim also makes extensive use of registers to temporarily store and manipulate text efficiently.

Emacs eschews modes and has a unified editing space. Its design emphasizes extensibility and customizability above all else. The editor is built on top of a Lisp interpreter that allows every function to be reprogrammed or augmented. Users can mold and extend Emacs by altering its source code. Emacs incorporates a "kitchen sink" philosophy of including a breadth of features, from email to games. Flexibility and universality are paramount in Emacs.

Both editors employ keybindings and shortcuts for efficiency, but Vim uses modal editing while Emacs utilizes chorded or combined key commands activated via modifier keys. This results in Vim having a steeper initial learning curve but allows fluid movement once mastered. Emacs' consistency of key commands can be more intuitive but requires memorizing myriad bindings. Ultimately, their design philosophies enable fast text editing but via different means.

Customization and Extensibility

Perhaps the greatest shared strength of Vim and Emacs is the ability to customize and extend their functionality through scripting languages and plugins.

Vim provides Vimscript for writing configuration scripts to customize bindings, settings, plugins, and more. Vimscript allows the creation of mappings, functions, auto commands, and other features to mold Vim to your needs. There is a thriving ecosystem of Vim plugins on sites like GitHub, offering extensions for everything from syntax highlighting to IDE-like capabilities. Some particularly popular options are plugins for fuzzy file search, snippets, and git integration.

Emacs' core customizability comes through Emacs Lisp, which gives complete control over the editor's behavior. Emacs treats everything as code that can be modified, right down to low-level functions. Emacs Lisp allows for custom keybindings, writing new functions, program modes, and more. Emacs maintains an ecosystem of packages adding functionality via ELisp libraries. Some popular packages provide interfaces to version control, programming support, and enhanced UI theming.

Vim and Emacs' scripting capabilities allow them to be shaped to suit any workflow. Both benefit from extensive custom plug-ins and configurations shared by active user communities. Overall, Emacs provides more customization breadth with Lisp while Vim offers depths in specific areas like editing. The extensibility makes both editors highly personal.

Interface and Editing Models

Vim and Emacs employ fundamentally different interfaces and text editing models.

Vim uses modal editing with at least three main modes: normal, insert, and visual. In normal mode, keystrokes trigger commands like d for delete or y for yank/copy. You manipulate text efficiently but cannot insert characters. Insert mode allows you to write text normally. Visual mode highlights text selections. Switching between modes is core to Vim's grammar. Advanced Vim users utilize normal mode for most operations, developing muscle memory for keyboard shortcuts.

Emacs uses key chords and modifier keys for commands. For example, Ctrl+K deletes a line. Commands are consistent across buffers. Emacs does not have a normal editing mode per se—you can enter text or issue commands at any time. Emacs has a unified editing space and avoids disrupting the user's flow. Advanced users develop "Emacs pinky" from heavy use of the Ctrl key.

Vim provides greater modal versatility but has a steeper initial learning curve. Emacs' unified approach is more intuitive upfront. Vim offers efficient text manipulation via composable single-key commands. Emacs allows fluid chording of commands during editing. Both support customizable keybindings. The modal vs unified space paradigms represents a core Vim vs Emacs divide.

Customization and Extensibility

Customization and extensibility are core strengths of both Vim and Emacs owing to their scripting capabilities and vibrant plugin ecosystems.

Vim provides Vimscript for customizing and extending functionality. Vimscript allows for:

  • Creating mappings to bind keys to commands

  • Writing new functions and plugins

  • Setting options and variables

  • Automatic commands to respond to events

  • Advanced scripting capabilities

Vim has a large community of plugins distributed via repositories like GitHub and Vim Awesome. Popular plugin categories include:

  • Syntax highlighting - customized rules for different languages

  • Snippets - insert code templates to speed up development

  • File navigation - fuzzy finding, file trees, buffers

  • Completion - autocomplete code and path suggestions

  • Git tools - commit, diff, browse without leaving Vim

  • IDE capabilities - code evaluation, linting, debugging

  • Productivity enhancers - bookmarks, search, scrolling

Emacs provides Emacs Lisp (ELisp) for modifying and extending every part of the editor, right down to the source code. ELisp allows for:

  • Rebinding keys and creating custom keybindings

  • Adding new commands and functions

  • Altering core Emacs behavior by redefining functions

  • Extending editor with new major and minor modes

  • Advanced programming capabilities

Emacs has a rich ecosystem of packages/modules adding features:

  • Programming support - debuggers, REPLs, project/code browsers

  • Completion tools - autocomplete, syntax checking

  • Version control - Magit, Git integration

  • Themes/UI modes - customize highlights, fonts, layouts

  • Productivity - snippets, references, documentation lookup

  • And much more - email, calendars, games, etc

Both editors offer extreme flexibility to customize and enhance productivity thanks to thriving plugin ecosystems tapping into their scripting capabilities.

Programming Support

With both Vim and Emacs being advanced text editors frequented by programmers, it's no surprise they offer extensive programming support features.

Vim provides many features aimed at coders, including:

  • Syntax highlighting - colored text based on language syntax

  • Automatic indentation - indent code blocks intelligently

  • Tag jumping - jump to definitions of code symbols

  • Integrated building/compiling for many languages

  • Code evaluation support for interpreted languages

  • Powerful search and code navigation shortcuts

  • Tight integration with version control systems

  • Linting and error highlighting in some languages

Emacs has deep programming language integration:

  • Major modes for most languages with syntax highlighting

  • Intelligent auto-indentation and code formatting

  • Integrated debugger support and REPLs for many languages

  • Project-aware code navigation and browsing

  • Code analysis tools - linting, profiling, coverage

  • Built-in compilation and building of projects

  • Code evaluation support for interpreted languages

  • Tight version control integration with Magit

  • Powerful symbol lookup and source code search

Overall, Vim provides efficient programming language editing out-of-the-box, while Emacs offers unparalleled customizability and much deeper programming language integration if properly configured. However, both editors can be enhanced significantly for programming via plugins and packages, matching the preferences of the user.

Help and Documentation

With their extensive features, Vim and Emacs both provide built-in documentation and help systems.

Vim has a comprehensive: help system that is accessible from within the editor. The built-in documentation includes:

  • User manual with a tutorial for beginners

  • Reference for commands, options, registers, shortcuts, etc

  • Info on plugins, scripting, customization, tips/tricks

  • Contextual help based on what the user was doing

  • Hyperlinked, searchable pages formatted for terminal

  • Ability to open help in vertical splits

In addition, Vim provides man pages for users comfortable with that Unix standard documentation system.

Emacs employs an interactive help system called Emacs Info. Features include:

  • browsable pages with Emacs basics, tutorials, references, etc

  • context-sensitive help pages based on the current mode

  • hyperlinked pages rendered in the Emacs window

  • ability to search documentation from within Emacs

  • CHEAT SHEET pages on shortcuts, commands organized by topic

  • info-look package integrates documentation browsing

Emacs documentation is very thorough but dense. Vim's docs are more concise and easier to quickly browse, suitable to reference. Both editors provide ample documentation accessible from within the editor.

Cross-Platform Support

A major advantage of both Vim and Emacs is their availability across different operating systems.

Vim originated as a text editor for Unix, but versions now exist for Linux, macOS, and Windows. There are GUI versions like gvim and MacVim. The editor also runs natively in terminal emulator windows on any platform. Vim is lightweight and straightforward to install on most systems.

Emacs was also originally built for Unix. However, early on it was ported to other platforms starting with GNU Emacs on UNIX-like systems. Today, GNU Emacs runs on Linux, Windows, macOS, and more. The native GUI version provides a consistent experience across platforms. The editor's basic keybindings and behavior remain unchanged.

Both Vim and Emacs are well supported across common contemporary platforms. Vim likely has better terminal application support, while Emacs shines more as a standalone desktop application. Plugins and scripting also work consistently for each editor across different OSes.

In summary, Vim and Emacs are both cross-platform editors that a user can install and use productively on Linux, macOS, Windows, and Unix systems. Their support for terminal and GUI use allows flexibility. The editors' behaviors remain constant regardless of the operating system.

Conclusion

Vim and Emacs represent divergent philosophies of text editing that still thrive today. This article delved into their origins, interfaces, customization features, and other aspects to contrast these iconic editors.

Vim follows a modal editing approach that prioritizes keyboard commands and efficiency. Its steeper learning curve pays off for power users and programmers looking to keep their hands on the keyboard. Emacs emphasizes endlessly customizable chorded commands and advanced programming integration through Lisp. Both reward users that invest time to customize and extend them.

For new users, Vim's unintuitive modes may frustrate at first compared to Emacs' more unified editing space. But Vim offers a greater focus for pure text and code editing once mastered. Emacs provides a more general-purpose work environment tailored to the user's specific needs.

There is no unambiguous winner in the Vim vs Emacs rivalry - one person's pros may be another's cons. Vim shines when snappy editing and lightweight utility matter most. Emacs is ideal for those who want endless customizability and programming-centric features. Both have stood the test of time and remain excellent, open-source choices cherished by advanced users. The decision often comes down to personal preference shaped by workflow, experience level, and philosophy.

Read: Essential Commands for Vim and Emacs

10
Subscribe to my newsletter

Read articles from James Mathenge directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

James Mathenge
James Mathenge

A highly skilled professional dev who possesses a unique combination of expertise in both Finance and Software Development