12

What packages are available for modal editing in Emacs? What do you use and why?

Let's try to post one package per answer. I propose mention advantages and shortcomings of every package.


Here is my definition of modal editing (I couldn't find dedicated Wikipeadia article):

Modal editing — style of text editing when user periodically switches usually between “normal mode” when keys do not cause inserting of their characters but perform various operations on text and “insert mode” when keys insert corresponding characters. There may be more modes, of course. Most modern editors are not modal. An example of modal text editor is Vi (Vim).

  • And what is "modal editing"? – Lindydancer Sep 15 '15 at 20:12
  • @Lindydancer, I added my attempt to explain the concept to the question. – Mark Karpov Sep 15 '15 at 20:21
13

evil, the Extensible VI Layer for Emacs

Questionable name aside, evil is the current state-of-the art when it comes to vim emulation in Emacs (and possibly anywhere else, for that matter). It supports a lot of features that other Vim emulation packages eschew, including:

  • vim textobjects
  • vim registers
  • vim keyboard macros
  • ex commands

Advantages

  • Key compatibility with vim means you don't lose your muscle memory when switching to systems without Emacs.
  • Very mature and widely used (lots of community packages, for example)
    • Many package for vim have been ported to evil.
  • vim style grammar is modular and lends itself very well to user extension
  • evil itself is very extensible: make your own textobjects, operators, and motions!

Disadvantages

  • Will probably require some fiddling to make it play nice with other packages
    • Fortunately, evil makes the most common use-cases ridiculously easy.
  • evil is a very complex system. Hacking on the evil core can become quite involved.
  • vim keybindings are not necessarily ergonomically optimal. Sometimes, they can feel a little arbitrary when ported to a different system.
  • Hosted on BitBucket (mercurial) make of this what you will.
  • I found the acronym evil for extensible vi layer for Emacs a little of a bad taste. – Name Sep 16 '15 at 9:56
  • @Name not my idea, but how so? – PythonNut Sep 16 '15 at 13:34
  • from a dictionary: evil=Profoundly immoral and malevolent, embodying or associated with the forces of the devil, harmful, extremely unpleasant, ... – Name Sep 16 '15 at 14:00
  • 3
    @Name as someone who has given him-/herself the name "Name", I would think you would appreciate the use of humor when naming things. :-) In the case of Evil, it's irony (see en.wikipedia.org/wiki/Irony#Definitions). I for one think it's one of the best names ever given to an Emacs package, and would list that as an advantage! – tarsius Sep 16 '15 at 14:24
  • @PythonNut I think the use of Bitbucket is less of a problem (actually no problem at all) than the use of Mercurial. – tarsius Sep 16 '15 at 14:25
10

There is god-mode (https://github.com/chrisdone/god-mode), which uses standard Emacs key bindings but removes the need to hold down modifiers. When god-mode is enable C-... bindings require no modifier and M-... bindings use a prefix rather than a modifier.

As an example from the github page:

Before: C-p C-k C-n M-^ ) C-j C-y M-r C-x z z M-2 M-g M-g C-x C-s

After: p k n g ^ ) j y g r . . 2 g g x s

  • 1
    Please expand your answer, so it's not just a link. – Mark Karpov Sep 16 '15 at 4:43
  • @Stefan - I took the liberty of expanding your answer a little bit. Feel free to change however you'd like. – glucas Sep 16 '15 at 13:22
  • glucas: Thanks! @Mark: not knowing anything more about god-mode, I couldn't easily expand my answer. I posted it in the hope that someone like glucas would fill in the blanks. – Stefan Sep 16 '15 at 13:46
6

Modalka must be the newest kid on the modal editing block. The github project seems to be all of 10 days old. I don't have enough usage time to comment or evaluate, but here's how it is described:

This is a building kit to help switch to modal editing in Emacs. Main goal of the package is making modal editing in Emacs as natural and native as possible. There is no hack, no corner cases, no emulation — just start edit modally the way you want.

The documentation also compares and contrasts Modalka with other common modal solutions, such evil, god-mode, boon, etc.

4

Adding my own, thanks @Mark for encouragement.

Xah Fly Keys

Designed from the ground up for emacs, with the goal of being the MOST efficient system, from years experience with ergoemacs-mode. Key choices are science based as much as possible, based on statistics of key frequency and key easy-to-press score. Most frequently used commands are mapped to the most easy-to-press keys. Other issues, such as grouping, and keybinding bigram, are also considered from 3 years of weekly experiment.

Interesting Points:

  • All C-x commands are done by sequence of 2 to 3 single keys. In xah-fly-keys, C-x is never necessary. M- is never necessary neither.
  • Does not conflict with any GNU emacs's keys, because it does not bind Ctrl or Meta (except C-7, C-8, but not essential). You can have xah-fly-keys on in insert mode, and use GNU Emacs the way you normally do.
  • Also considered what set of commands results in max editing efficiency. So, the package uses ~80 custom editing commands. (for example, copy will copy current line if there's no selection. One single command to toggle letter case, instead of GNU Emacs's ~6 variations of upper/lower/region/no-region.)
  • The implementation is as simple as possible. No macro, no advice, no complex remapping of keys, only a couple hooks are used. (good or bad?!)

Disadvantages:

  • Like learning vi for the first time, you'll need one month to adopt.
  • Not well known. Just released for public use this month.
  • Currently support Dvorak layout only.
  • No convenient key diagram for learning (yet).
  • For major modes, you still need to use C-c. (so, you might use other packages such as god-mode or hydra to solve this problem.)

I'm the author, so be warned that I may be unconciously biased. Feel free to comment or correct.

  • Any chance you'll support other keyboard layouts? I know ErgoEmacs does. I might give it a try, but the bar of switching to Dvorak is too high for a casual experiment. – PythonNut Sep 16 '15 at 17:31
  • @PythonNut yes, top priority. I hope in a week. Main thing is figure how how i want to implement it. – Xah Lee Sep 16 '15 at 18:55
  • Ah. Very cool. I'll give it a whirl when it comes out. – PythonNut Sep 16 '15 at 19:07
3

Boon

Boon is one of less-known packages for modal editing. It doesn't emulate Vi (or Vim) but provides original layout optimized for Colemak keyboard layout.

Advantages and Design Principles

  • Spacial allocation first, mnemonics second: the allocation of keys to commands is based in priority on the locations of keys on the keyboard. Whatever is printed on the key cap is a secondary concern.

  • Easy finger rolls: common combination should either be left/right hand alternation or easy one-hand rolls.

  • Use of home row and strong fingers for the most used commands

  • Easy navigation: many commands are bound to navigation. This facilitates moving around. Because movements double up as region-definitions, it makes manipulation commands (operators) more powerful.

Disadvantages

  • You need to type Colemak.

  • You need to re-learn how to interact with the editor since collection of editing primitives and their placement on keyboard are quite unique.

  • 1
    It sounds a bit strange that Boon doesn't really care about what's on the key, yet enforces that the keys be Colemak. It sounds like it should be layout agnostic. – PythonNut Sep 16 '15 at 15:14
  • @PythonNut, I guess people need to refer to keys somehow :-) I think it's entirely possible to make it work with other layouts. – Mark Karpov Sep 16 '15 at 15:18
3

Ergoemacs also supports modal editing. It doesn't emulate vi, but uses Alt key for most frequently used commands. For example, moving cursor is Alt plus right hand inverted T. (On QWERTY it is Alt+j for left, Alt+l for right, Alt+i for up and Alt+k for down). Deleting char or word is Alt with left hand home-row keys. Key choices are based on command frequency and key's position for ease-of-press.

  • To start modal editing, the user can press f6.
    • Once f6 was pressed, the most frequently used keys no longer require an alt key combination.
    • Therefore, on QWERTY, j is left, j is right, i is up and k is down).
  • The modal command mode is exited by pressing return, f6 or escape.

In addition to the traditional modal paradigm, there is a quasi modal paradigm that allows any C-x or C-c key combination to be reached without using any modifiers (like god-mode).

  • The quasi-modal is started with the QWERTY apps f for C-c with the control key pressed down and the QWERTY apps d for C-x.
  • While completing this key sequence the apps key will change the type of modifiers that are assumed to be pressed down.
  • Once the command has been called, ergoemacs resumes the editing mode.
  • During any key sequence you can also change the types of keys that are held down. This is by simply pressing the apps key again.

In addition to changing the command keys, ergoemacs-mode allows you to change things about the key sequence while typing it:

  • You can edit the prefix argument during the middle of a key sequence by pressing f2.
  • Pressing backspace takes back the last key pressed.
  • Apps allows you to change the keys held down during any key sequence.

ergoemacs-mode also attempts to respect anything the mode does to the fundamental keys. For example, if org-mode defines a special key for next-line, ergoemacs uses this command for Alt+k when in org-mode.

Advantages:

  • Part of GNU Emacs, in ELPA.
  • Supports “universal” Windows/Linux keys out of the box. e.g. Open (C-o), Close (C-w), Select all (C-a), Copy (C-c), Cut (C-x), Paste (C-v), etc.
  • Fairly popular.
  • Supports many layouts, including Qwerty, dvorak, colemak, bepo, and many other international layouts that adjust the keys to make sure they are on the home row (M-i in QWERTY would be M-u in colemak).
  • Shows an image of your keyboard layout in emacs by describing the theme.
  • Keys are customizable via a extension system, by creating a theme.
  • You can setup any arbitrary modal keymap (not yet documented).

Disadvantages:

  • Stable is slow on startup.
    • In the unstable master, the first startup is slow (~5 seconds for minimal setup), (~20 seconds for my startup)
    • The second second startup is much quicker (for my complex setup it is ~4 seconds).
    • This is because ergoemacs-mode is changing and caching every active keymap in emacs. On second startup, these settings are saved.
  • Complex code.

See https://github.com/ergoemacs/ergoemacs-mode

2

Another semi-modal option is Hydra:

https://github.com/abo-abo/hydra

According to the website

Imagine that you have bound C-c j and C-c k in your config. You want to call C-c j and C-c k in some (arbitrary) sequence. Hydra allows you to:

  • Bind your functions in a way that pressing C-c jjkk3j5k is equivalent to pressing C-c j C-c j C-c k C-c k M-3 C-c j M-5 C-c k. Any key other than j or k exits this state.

  • Assign a custom hint to this group of functions, so that you know immediately after pressing C-c that you can follow up with j or k.

I haven't used it but it seems interesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.