vim

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 3 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 vim is the modal editing ZPad offers when Vim mode is on: the modes, the motions and operators, and the text objects. It knows nothing of MyGo's widgets: the app gives a Host the text to read, the caret and selection to move, and the edits to make.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	Len() int
	LineCount() int
	Line(i int) string
	LineStart(i int) int
	LineEnd(i int) int
	LineOf(offset int) int
	Slice(start, end int) string
}

Buffer is the text the session reads, as editor.Snapshot is.

type Host

type Host interface {
	Text() Buffer
	Cursor() int
	SetCursor(offset int)
	SetSelection(anchor, head int)
	Replace(start, end int, text string)
	Undo() bool
	Redo() bool
	MoveToBracket() bool
	Page(forward bool) bool
	FindNext(previous bool, currentStart, currentEnd int) (start, end int, ok bool)
	OpenCommandLine(kind rune)
	Save()
	Close()
	SaveAndClose()
	GoToLine(line int)
	Indent() string
	ReadOnly() bool
	ReadClipboard() string
	WriteClipboard(text string)
}

Host is what the session asks of the app. It is implemented by a few lines over an editor.State, so that the session itself needs no UI.

type Key

type Key uint8

Key is a key that is not text: the keys a terminal names, and the few control keys Vim uses.

const (
	KeyNone Key = iota
	KeyEscape
	KeyEnter
	KeyBackspace
	KeyDelete
	KeyTab
	KeyLeft
	KeyRight
	KeyUp
	KeyDown
	KeyHome
	KeyEnd
	KeyPageUp
	KeyPageDown
	KeyCtrlR
)

type Mode

type Mode uint8

Mode is what keys mean now.

const (
	// Normal is Vim's normal mode: keys are commands and the caret sits
	// on a character.
	Normal Mode = iota
	// Insert is the editor as it always is: keys type text.
	Insert
	// Visual selects characters, VisualLine whole lines.
	Visual
	VisualLine
)

type Range

type Range struct {
	Start, End int
	Linewise   bool
}

Range is a piece of the text: bytes Start to End, End exclusive, and whether the whole lines are meant, as dd and V select.

type Session

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

Session is one tab's modal state: its mode, the count and operator being typed, the visual selection, and the unnamed register.

func New

func New() *Session

New returns a session in normal mode.

func (*Session) GoToLine

func (s *Session) GoToLine(h Host, line int)

GoToLine is the app's part of a :<line> command.

func (*Session) Key

func (s *Session) Key(k Key, h Host) bool

Key feeds a key that types no text.

func (*Session) Mode

func (s *Session) Mode() Mode

Mode returns what keys mean now.

func (*Session) Normal

func (s *Session) Normal(h Host)

Normal is for the app after a command line edit.

func (*Session) Pending

func (s *Session) Pending() bool

Pending reports whether a count or an operator is being typed, which the app may show in the status bar and underline the caret for.

func (*Session) Reset

func (s *Session) Reset()

Reset puts the session in normal mode with nothing pending, as turning Vim mode off or opening a preview does.

func (*Session) Rune

func (s *Session) Rune(r rune, h Host)

Rune feeds a typed character, in normal or visual mode. Insert mode is the editor's own, so it is the app's to let through.

func (*Session) SetSearchRange

func (s *Session) SetSearchRange(start, end int)

SetSearchRange remembers the match the app just found, so that n and N continue after it rather than finding it again.

func (*Session) Text

func (s *Session) Text(text string, h Host) (left string)

Text feeds the characters of an InputText event. It returns the text that is left once the session entered insert mode, which the app inserts as typing does: a paste of ihello enters insert at i and types hello.

Jump to

Keyboard shortcuts

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