nvim

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 14 Imported by: ? 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 nvim runs an embedded Neovim for the split view's source pane: nvim --embed with the ext_linegrid UI, editing a buffer kept in step with the notebook's text. The page draws the grid; this package passes its redraw events on and the page's keys back.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("nvim not found")

ErrNotFound is Find's error when there is no nvim to use.

View Source
var MinVersion = Version{0, 10, 0}

MinVersion is the oldest Neovim that works: 0.9 has no inline virtual text.

View Source
var StartTimeout = 5 * time.Second

StartTimeout is how long Start waits for Neovim and the user's config.

Functions

This section is empty.

Types

type Editor

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

Editor is one running Neovim.

func Start

func Start(o Options) (*Editor, error)

Start starts Neovim and attaches to it as its UI.

func (*Editor) ApplyLines

func (e *Editor) ApplyLines(seq int, edits []LineEdit) (bool, error)

ApplyLines makes edits on the buffer, in order and not overlapping, made against its text as of seq. If the buffer has typing since that wasn't sent, or seq isn't the buffer's, it changes nothing and reports false; the typing is then sent, as Lines, to fold in before trying again. Done, it moves the buffer's seq on one.

func (*Editor) Call

func (e *Editor) Call(fn, args string) (string, error)

Call calls the function called fn in the buffer's mdsh side with args, a JSON array, and returns what it returns, as JSON.

func (*Editor) Close

func (e *Editor) Close() error

Close quits Neovim.

func (*Editor) Input

func (e *Editor) Input(keys string) error

Input types keys, in Neovim's key notation such as "<C-w>".

func (*Editor) Mouse

func (e *Editor) Mouse(button, action, mod string, row, col int) error

Mouse passes on a mouse event: button is "left", "right", "middle" or "wheel"; action is "press", "drag" or "release", or for the wheel "up", "down", "left" or "right"; mod is like "C" or "S-A" or "".

func (*Editor) Paste

func (e *Editor) Paste(text string) error

Paste pastes text as one undoable change.

func (*Editor) Resize

func (e *Editor) Resize(cols, rows int) error

Resize asks for a grid of cols by rows.

func (*Editor) Saved

func (e *Editor) Saved() error

Saved marks the buffer unchanged, once its text is written.

func (*Editor) Snapshot

func (e *Editor) Snapshot() (string, int, error)

Snapshot is the buffer's text, each line ending with a newline, and its seq, for a page catching up with a Neovim already running. What was typed and not yet sent is sent first, as Lines, and is in both.

type Found

type Found struct {
	Path    string  `json:"path"`
	Version Version `json:"version"`
}

Found is a Neovim found by Find.

func Find

func Find(path string) (Found, error)

Find finds the nvim to use: path if it isn't empty, else nvim on the PATH, else the first of the usual places that has one. It is an error if that nvim is older than MinVersion.

type LineEdit

type LineEdit struct {
	First int    `json:"first"`
	Last  int    `json:"last"`
	Text  string `json:"text"`
}

LineEdit replaces lines [First, Last) with Text, whole lines.

type Lines

type Lines struct {
	Seq   int    `json:"seq"`
	First int    `json:"first"`
	Last  int    `json:"last"`
	Text  string `json:"text"`
}

Lines says lines [First, Last) of the buffer's text, counted from 0, became Text, whole lines each ending with a newline. Seq counts what changed the text, as the buffer sends it: what was typed, and each ApplyLines.

type Options

type Options struct {
	Path       string
	Cols, Rows int
	// Name is the buffer's name, such as mdsh://notes.md.
	Name string
	Text string
	// Clean starts Neovim without the user's config.
	Clean bool
	// Dark sets 'background' to dark, else light, before the config
	// runs, which may set it again.
	Dark bool
	// LSP is the command that starts mdsh's language server, which the
	// buffer attaches to for completion, hover help and diagnostics.
	// Empty starts none.
	LSP []string

	// Redraw gets the redraw events up to each flush, as Neovim sent
	// them: each is the event's name and then one argument list for
	// each time it happened.
	Redraw func(events [][]any)
	// Lines gets what was typed in the buffer, a moment after: the lines
	// that changed.
	Lines func(Lines)
	// Write is called for :w, with the Seq of the last Lines it follows.
	Write func(seq int)
	// Event gets what the buffer's mdsh side reports, such as the
	// cursor moving or :RunBlock: the event's name and its data as JSON.
	Event func(name, data string)
	// Exit is called once Neovim has quit, with why if it failed.
	Exit func(err error)
}

Options are how to start an Editor.

type Version

type Version struct {
	Major, Minor, Patch int
}

Version is a Neovim version.

func ReadVersion

func ReadVersion(path string) (Version, error)

ReadVersion runs nvim --version, which reads no config.

func (Version) Less

func (v Version) Less(w Version) bool

Less reports whether v is older than w.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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