Toby 'qubit' Cubitt - Evil cursor model

submited by
Style Pass
2021-06-20 07:30:06

I recently got enticed by Vim's text editing model, and began my own personal descent into evil-(mode): the full-featured Vim implementation within Emacs itself.11 1Viewed as a text-based application framework come operator system come Lisp machine, Emacs wins hands down. It's a pretty decent text editor, too. But Vim's combination of modal editing and, in particular, composable commands as a text editing language is compelling.

The cursor in a text editor indicates the location where the next editing operation should act, both visually to the user and internally to the text editor. There are two conceptually different ways to model the cursor location. You can consider the cursor to be located in between two consecutive characters. Or you can consider it to be located on top of a particular character. Emacs, like almost every other text editor, uses the first model. If the cursor22 2The "point", in Emacs terminology is at location 3, say, Emacs considers it to be between the 2nd and 3rd character in the text.33 3Emacs indexes cursor locations from 1 rather than 0; if the point is located just before the first character in the buffer, the value of point is equal to 1, and that is the minimum possble value it can take. Typing a character will insert it in between these two characters; deleting backwards will delete character 2; deleting forwards will delete character 3.

Vim also uses this cursor model in insert mode.44 4I'll use the Vim terminology here, but note that evil-mode calls modes states – so /insert state and normal state – to avoid confusion with Emacs' major- and minor-modes, which are something altogether different. But in normal mode, it uses the other cursor model: if the cursor is at location 3, in normal mode Vim considers it to be located on top of the 3rd character in the text. There are therefore two insersion commands: i will start inserting text just before the 3rd character (i.e. in between characters 2 and 3); a will start inserting text just after the 3rd character (i.e. in between characters 3 and 4). Similarly, p pastes text before the character under the cursor, whereas P pastes it after that character.

Leave a Comment