vimedit

package
v0.271.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vimedit is a vim-style line-buffer editing engine for the playground model editor. It has no rendering or UI dependencies: the host feeds keys in and reads the buffer, cursor, mode and status back out.

The buffer is a slice of lines, each an immutable []rune (copy-on-write), so an undo snapshot is a shallow copy of the outer slice and every keypress costs O(line length) or O(lines) pointer work, never a join/split of the whole text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action tells the host what to do after a key was handled.

const (
	None       Action = iota
	Apply             // :w, :wq, :x — host validates and applies
	Close             // :q, or Esc in Normal mode with nothing pending
	ForceClose        // :q! — close without confirming
)

The actions a key can request from the host.

type Editor

type Editor struct {
	// contains filtered or unexported fields
}

Editor is the editing engine. Create it with New; methods take a pointer receiver but the type itself is safe to store by value.

func New

func New() Editor

New returns an empty editor in Insert mode.

func (*Editor) CommandLine

func (e *Editor) CommandLine() string

CommandLine is the prompt char plus typed text in Command mode, else "".

func (*Editor) Cursor

func (e *Editor) Cursor() Pos

Cursor is the current cursor position.

func (*Editor) HandleKey

func (e *Editor) HandleKey(k Key) Action

HandleKey processes one key press and reports what the host should do.

func (*Editor) InsertText

func (e *Editor) InsertText(s string)

InsertText inserts pasted text at the cursor as one undo step.

func (*Editor) Line

func (e *Editor) Line(i int) []rune

Line returns line i as a read-only view; callers must not modify it.

func (*Editor) LineCount

func (e *Editor) LineCount() int

LineCount is the number of buffer lines (always at least one).

func (*Editor) Mode

func (e *Editor) Mode() Mode

Mode is the current mode.

func (*Editor) Pending

func (e *Editor) Pending() string

Pending is the not-yet-complete count/operator/prefix keys, for a showcmd area.

func (*Editor) Revision

func (e *Editor) Revision() uint64

Revision increments on every text change, never on pure cursor moves.

func (*Editor) Selection

func (e *Editor) Selection() (Selection, bool)

Selection returns the Visual selection; ok only in Visual and VisualLine.

func (*Editor) SetTop

func (e *Editor) SetTop(top int)

SetTop tells the engine the first visible row (for H/M/L).

func (*Editor) SetValue

func (e *Editor) SetValue(s string)

SetValue replaces the buffer, resets the cursor, history and mode (Insert).

func (*Editor) SetViewportHeight

func (e *Editor) SetViewportHeight(h int)

SetViewportHeight sets the page size used by ctrl+d/u/f/b and H/M/L.

func (*Editor) Status

func (e *Editor) Status() string

Status is the last transient message; cleared at the start of the next HandleKey.

func (*Editor) Value

func (e *Editor) Value() string

Value returns the buffer joined with "\n". The result is cached by revision.

type Key

type Key struct {
	Name string // e.g. "a", "ctrl+d", "esc", "enter", "space", "backspace"
	Text string // printable text, "" for control and named keys
}

Key is one key press, mirroring tea.KeyPressMsg.

type Mode

type Mode int

Mode is the editor's current input mode.

const (
	Insert Mode = iota
	Normal
	Visual
	VisualLine
	Command // ":" ex line, or "/" "?" search line
)

The editor modes. Insert is the zero value: a new editor opens in Insert.

func (Mode) String

func (m Mode) String() string

String returns the status-line label of the mode.

type Pos

type Pos struct{ Row, Col int }

Pos is a buffer position in rune indices.

type Selection

type Selection struct {
	Start, End Pos
	Linewise   bool
}

Selection is the Visual-mode selection, ordered (Start <= End). End is inclusive in charwise mode; in linewise mode only the rows matter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL