Up to now, I have used vi as an example for modal text editor, mostly because I expect most programmers have at least heard of it. However, I don’t believe vi and clones are the best modal text editor out there.

I have been working, for the last 5 years, on a new modal editor called Kakoune. It first started as a reimplementation of Vim (the most popular vi clone) whose source code is quite dated. But, I soon realized that we could improve a lot on vi editing model.

At the lower level, the problem is that vi treats moving around and selecting an object as two different things. Kakoune unifies that, moving is selecting. w does not just go to the next word, it selects from current position to the next word. By convention, capital commands tend to expand the selection, so W would expand the current selection to the next word.

Kakoune tries hard to fix one of the big problems with the vi model: its lack of interactivity. Because of the verb followed by object grammar, vi changes are made in the dark, we don’t see their effect until the whole editing sentence is finished. 5dw will delete to next five words, if you then realize that was one word too many, you need to undo, go back to your initial position, and try again with 4dw . In Kakoune, you would do 5W , see immediately that one more word than expected was selected, type BH to remove that word from the selection, then d to delete. At each step you get visual feedback, and have the opportunity to correct it.

Kakoune’s grammar is object followed by verb , combined with instantaneous feedback, that means you always see the current object (In Kakoune we call that the selection) before you apply your change, which allows you to correct errors on the go.

vi basic grammar is verb followed by object ; it’s nice because it matches well with the order we use in English, "delete word". On the other hand, it does not match well with the nature of what we express: There is only a handful of verbs in text editing ( d elete, y ank, p aste, i nsert…​), and they don’t compose, contrarily to objects which can be arbitrarily complex, and difficult to express. That means that errors are not handled well. If you express your object wrongly with a delete verb, the wrong text will get deleted, you will need to undo, and try again.

Multiple selections

Another particular feature of Kakoune is its support for, and emphasis towards the use of multiple selections. Multiple selections in Kakoune are not just one additional feature, it is the central way of interacting with your text. For example there is no such thing as a "global replace" in Kakoune. What you would do is select the whole buffer with the % command, then select all matches for a regex in the current selections (that is the whole buffer here) with the s command, which prompts for a regex. You would end up with one selection for each match of your regex and use the insert mode to do your change. Globally replacing foo with bar would be done with %sfoo<ret>cbar<esc> which is just the combination of basic building blocks.

Global replace Your browser does not support the video tag.

Multiple selections provides us with a very powerful to express structural selection: we can subselect matches inside the current selections, keep selections containing/not containing a match, split selections on a regex, swap selections contents…​

For example, convert from snake_case_style to camelCaseStyle can be done by selecting the word (with w for example) then subselecting underscores in the word with s_<ret> , deleting these with d , then upper casing the selected characters with ~ . The inverse operation could be done by selecting the word, then subselecting the upper case characters with s[A-Z]<ret> lower casing them with ` and then inserting an underscore before them with i_<esc> This operation could be put in a macro, and would be reusable easily to convert any identifier.

Camel case to snake case Your browser does not support the video tag.

Another example would be parameter swapping, if you had func(arg2, arg1); you could select the contents of the parenthesis with <a-i>( , split the selection on comma with S, <ret> , and swap selection contents with <a-)> .

Swapping arguments Your browser does not support the video tag.

It is as well easy to use multiple selections for alignment, as the & command will align all selection cursors by inserting blanks before selection start

Aligning variables Your browser does not support the video tag.

Or to use multiple selections as a way to gather some text from different places and regroup it in another place, thanks to a special form of pasting <a-p> that will paste every yanked selections instead of the first one.