> On 2019-02-18 09:04, ropers wrote: > [...] >> vi(1) has a feature where pressing ESC while in command-line mode >> (i.e. entering an ex command in command mode) will sometimes cancel >> the current line of ex input, but other times will have the same >> effect as if the user had pressed return.
On 19/02/2019, Alessandro DE LAURENZIS <jus...@atlantide.t28.net> wrote: > I'm not an expert, but this behavior seems to be in line with POSIX [1] > requirements: > > [...] > <ESC> > Synopsis: > <ESC> > > If input was part of a line-oriented command: > > If interrupt was entered, text input mode shall be terminated and the > editor shall return to command mode. The terminal shall be alerted. > > If <ESC> was entered, text input mode shall be terminated and the > command shall continue execution with the input provided. > > Otherwise, terminate text input mode and return to command mode. > [...] > > In nvi, it is consistent among all line-oriented commands (:, /, ? and > !). > > Just my 2 cents > > [1] http://pubs.opengroup.org/onlinepubs/9699919799/ That's still a frames-based webpage. The direct link you probably intended is this: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html Or, more directly: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_97 Thanks for the POSIX hint. Sadly, that page still leaves me confused, or maybe the spec is bad, and I would welcome further advice from you or others. (That said, to my understanding OpenBSD tries to Do The Right Thing more so than follow any spec, so perhaps discussing the spec's merit is getting off-topic. If the spec is off-topic, I'd still welcome further replies to my original question. If people would prefer I took this to another forum, I'd welcome suggestions on where to go.) Here's what has me confused about that POSIX spec: 1. There is another ESC-related section on that vi page: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_16 "Terminate Command or Input Mode" However, that section is about how ESC behaves either in command (aka normal) mode or in input (aka insert) mode, and that's arguably different from how ESC behaves when typing (visible) command lines at the bottom. Technically *command-line mode* (as entered by :, /, ? and !etc) is a different mode; cf. here: https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes That's at least according to how most vi and vim experts describe things. Granted, that POSIX spec does not explicitly state that command-line mode is a separate mode; it speaks of "line-oriented commands", but whether this part of vi is called a separate mode or not is ultimately just semantics. However, *if* the POSIX spec considers command-line mode a part of command mode, then that section *would* seem to apply to command-line mode, and it *differs* from the section you quoted, and according to it, ESC should *not* behave like return. 2. The <ESC> section you quoted is part of a list of possible input, and on top of that list, just above the NUL section (how do you even input that off the keyboard?), <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_89> it says: "The following specifications are for command characters entered during text input mode." The headline above that reads, "Input Mode Commands in vi". However, in the specifications that follow, there are multiple references to line-oriented command input, so which is it? Even if we accept that command-line mode is part of command mode, clearly neither are part of text input mode (i.e. insert mode). So this is very inconsistent. I also really don't like the phrasing, "If input was part of a line-oriented command", because many *commands* in input mode are arguably line-oriented (e.g. d2d, y5y) , and many commands in command-line mode are arguably not really line oriented (e.g. :%s/foo/bar), at least in their effects. Moreover, the explicit references to terminating "text input mode" seem to imply that the user is in insert mode. So if the ESC-equals-return behaviour was implemented as a result of the POSIX spec like you suggest, then it seems to me that this may have been based on a misreading of a very confusing spec. Or is it just me who's confused? Clarifications welcome. Thanks and regards, Ian PS: Considering what it says here: <https://man.openbsd.org/vi#DESCRIPTION>, I would be very interested in hearing whether the ESC-equals-return behaviour existed in the original 4BSD vi. Does anyone know? PPS: Under Fast Startup <https://man.openbsd.org/vi#FAST_STARTUP>, man vi says: "There is only one key that takes you out of input mode, and that is the ⟨escape⟩ key", but under vi Text Input Commands, <https://man.openbsd.org/vi#VI_TEXT_INPUT_COMMANDS> it says: "⟨interrupt⟩ Interrupt text input mode, returning to command mode. The ⟨interrupt⟩ character is usually ⟨control-C⟩." Do people think that that's a contradiction? Arguably, control-C is not "one key", but still. Also, is the second quote saying users should normally press control-C, not ESC, to escape insert mode? That would be very at odds with everywhere and everyone else. There's similar wording at the bottom of the vi Commands section, <https://man.openbsd.org/vi#VI_COMMANDS>: "⟨interrupt⟩ Interrupt the current operation. The ⟨interrupt⟩ character is usually ⟨control-C⟩." Again, are we trying to say, just get used to "usually" using control-C there instead of ESC?