Documentation
¶
Overview ¶
Package vim is the modal input model, as a pure state machine.
It knows nothing about editors, terminals or SQL: keys go in, commands come out. Keeping it that way is what makes the interesting part — which half-typed sequences mean what — testable without a screen.
The scope is deliberately the practical subset: normal, insert and visual modes with the common motions, operators and edits. Counts (3dd), search (/), marks, named registers and dot-repeat are out.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Kind Kind
Motion Motion
// At is where an insert or a put lands.
At Place
// Linewise means whole lines: dd, yy, V.
Linewise bool
// Selection means the operator applies to the visual selection already on
// screen rather than to a motion from the cursor.
Selection bool
}
Command is a completed instruction for the editor.
It is a comparable value with no pointers, so tests can state the whole expected command in one literal.
type Entry ¶
type Entry struct {
// Keys is the sequence exactly as it is typed, so that the reference can
// be checked against the state machine rather than trusted.
Keys string
Description string
}
Entry is one line of the key reference.
type Group ¶
Group is a titled section of the reference.
func Reference ¶
func Reference() []Group
Reference lists the modal commands for the help screen and `dv keys`.
It lives beside the state machine on purpose. A reference kept anywhere else drifts, and a key reference that lies is worse than none — it is consulted precisely when something has already stopped working.
type Kind ¶
type Kind int
Kind is what a command does.
const ( // KindNone is the zero command, returned alongside any outcome that is // not OutcomeExecute. KindNone Kind = iota KindMove KindDelete KindChange KindYank KindPaste KindUndo KindRedo // KindInsert enters insert mode at At. KindInsert // KindVisual starts or ends a selection; Linewise says which kind. KindVisual // KindEscape returns to normal mode, collapsing any selection. KindEscape )
type Outcome ¶
type Outcome int
Outcome says what the state machine did with a key.
Three outcomes rather than a bool: "the editor should type this" and "I am waiting for the rest of a sequence" are different things, and collapsing them is how a half-typed operator ends up inserting a letter.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the modal input state: the current mode and any half-typed sequence.
It is not safe for concurrent use, which is fine — keys arrive one at a time on the interface's own goroutine.
func (*State) Feed ¶
Feed offers a key to the state machine.
The outcome says whether the editor should type the key, keep waiting, or run the returned command.
func (*State) Pending ¶
Pending renders the half-typed sequence for the status bar.
Showing it is not a nicety: an operator that silently waits for a motion is indistinguishable from a keyboard that has stopped working, and that is the single most likely way a new user concludes the application is broken.