|
|
Subscribe / Log in / New account

Making Emacs popular again

Making Emacs popular again

Posted May 8, 2020 16:22 UTC (Fri) by jem (subscriber, #24231)
In reply to: Making Emacs popular again by marcH
Parent article: Making Emacs popular again

>What fascinates me is: vim is apparently the last _modal_ editor left. I don't think I could ever get used to "modal editing", because I _always_ forget which mode I am in. Anyone knows what's wrong with me?

My biggest problem with vi is not that it is modal, I can get used to that. I think the strangest thing about vi is how it handles the cursor. "Normal" editors use the cursor to specify a point between two characters, or before the first character on the line, or after the last character on the line. If there are N characters on the line, the cursor can have N+1 positions.

Vi, on the other hand, uses the cursor to mark the character it is on. The exception is of course if the line is empty, in which case the cursor has nowhere to go, so it is displayed in the first column. This also means we need both an "insert" and an "append" command to enter insert mode, to add text either to the left or the right side of the cursor. Once in insert mode, vi starts treating the cursor exactly like all other editors do: text is inserted at the left edge of the cursor and the cursor is moved forward past the inserted character. When insert mode is exited, vi goes back to its normal behavior and realizes the cursor can't be left hanging mid-air, so it moves the cursor back one step, which is really confusing.

If somebody has a good explanation why vi is implemented like this, I'd like to hear it.


to post comments

Making Emacs popular again

Posted May 8, 2020 17:21 UTC (Fri) by mpr22 (subscriber, #60784) [Link] (1 responses)

Much of vi's design arises from the fact that Bill Joy was using a 300 baud Lear-Siegler ADM-3A terminal when he wrote it.

Making Emacs popular again

Posted May 10, 2020 14:42 UTC (Sun) by jem (subscriber, #24231) [Link]

And yet, Emacs could be used on an ADM-3A in the mid 1980s with no problem. Using Emacs back then felt very much like using a modern version of Emacs on a text terminal.

Making Emacs popular again

Posted May 8, 2020 17:46 UTC (Fri) by epa (subscriber, #39769) [Link] (4 responses)

Surely there are some vi-like editors which fix this off-by-one design error?

Making Emacs popular again

Posted May 12, 2020 4:04 UTC (Tue) by filbranden (guest, #87848) [Link] (3 responses)

> Surely there are some vi-like editors which fix this off-by-one design error?

It's just one setting away on Vim:

set virtualedit=onemore

You might still find some of the behavior a bit unexpected. For example, $ moves to the last character of the line, rather than one past.

Also, you might just break so many plug-ins this way :-)

But yeah, it's available as a configuration option.

Making Emacs popular again

Posted May 13, 2020 11:07 UTC (Wed) by jem (subscriber, #24231) [Link] (2 responses)

>It's just one setting away on Vim:
>set virtualedit=onemore

Ok, thanks. But this is only a partial solution. As you said, $ does not work, and pressing <esc> in insert mode still moves the cursor one position left. You would think i<esc> (entering insert mode and immediately exiting) would be a no-op, but no. My biggest problem with this setting, though, is that it is not supported in VS Code's vim emulator, which is my main use case for vim: to replace VS Code's Notepad-like default editor with a real editor.

Making Emacs popular again

Posted May 13, 2020 12:10 UTC (Wed) by karkhaz (subscriber, #99844) [Link] (1 responses)

Does writing "inoremap <esc> <esc>l" in your vimrc implement the behaviour you expect?

Making Emacs popular again

Posted May 13, 2020 17:43 UTC (Wed) by jem (subscriber, #24231) [Link]

With this setting I can get rid of the backward jump. But I guess I'd better get used to the standard behavior of (n)vi(m), even if it feels like I am dragging along a single character selection with the movement commands -- a selection I can extend with the v command, but never wholly get rid of.

There's a lot to like about vi, too, for example how you are able to combine editing commands with movement commands. At least you don't have to reach for the arrow keys all the time.

Making Emacs popular again

Posted May 9, 2020 0:17 UTC (Sat) by karkhaz (subscriber, #99844) [Link]

This design makes perfect sense to me.

In normal mode, you sometimes want to operate on characters. Commands like replace ('r'), substitute ('s'), delete ('x') work on the character that the cursor is on, unless of course you prefix the command with a number (in which case the command operates across a span of text, but still starting on the character that the cursor is on). It would not make sense for the cursor to be at the beginning of the line, before any characters, because what character are you operating on?

In insert mode, as you say, the cursor acts like in other editors, because insert mode is the mode that is akin to other editors.

Somebody else made a comment about the cursor changing its shape based on the mode---that seems like a very helpful way to understand this difference, what an excellent feature! In insert mode, you can have the pipe-cursor before the first character on the line, because you can start inserting text before the first character. In normal mode, the cursor is an underline, and the action operates on the character that is underlined. The underline cannot move before the first character or after the last, since there's no character for it to operate on.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds