Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Events

What greed.on(event, handler) hands each handler. Give the handler’s parameter the type named here, as in function(event: greed.BufferChanged), and the type checker catches a misspelled field. When each event happens is in Writing plugins; space h e (:describe-event) shows the same in the editor.

mode.changed

Its handler gets a greed.ModeChanged. A client’s mode changed. Handlers run as that client.

{
	client: number,
	from: string,
	to: string,
}

buffer.changed

Its handler gets a greed.BufferChanged.

{
	buffer: Buffer,
	--- On "buffer.changed": the first and last line (0-based, as the text is
	--- now) of what changed since the last "buffer.changed" for the buffer.
	from_line: number?,
	to_line: number?,
}

keys.pending

Its handler gets a greed.KeysPending.

{
	--- The client typing them, which handlers run as.
	client: number,
	--- The unfinished key sequence, e.g. "space"; "" once it's finished.
	keys: string,
}

command.run

Its handler gets a greed.CommandRun.

{
	--- The client it runs for, which handlers run as.
	client: number,
	--- The command about to run.
	name: string,
	--- The keys that ran it, when keys did, e.g. "g g".
	keys: string?,
	--- The number typed before the keys.
	count: number?,
}

lsp.diagnostics

Its handler gets a greed.DiagnosticsChanged.

{
	buffer: Buffer,
}

message

Its handler gets a greed.Message. What the status line is about to show. What a handler echoes shows instead, and isn’t told again.

{
	text: string,
	--- Something failed: an error, or a command that refused.
	error: boolean,
}

control.request

Its handler gets a greed.ControlRequest. A request from the session socket, e.g. from greed ctl or an agent. Answer it with greed.control.reply.

{
	id: number,
	--- "socket" for the session socket (greed ctl, greed mcp), "ide" for Claude
	--- Code's IDE connection.
	client: string,
	--- The session socket connection it came on, for `greed.control.send`;
	--- nil for Claude Code's IDE connection.
	connection: number?,
	--- The JSON-RPC id as the client sent it, the one a later
	--- `notifications/cancelled` names; nil for a notification.
	rpc_id: any,
	method: string,
	params: any,
}

control.closed

Its handler gets a greed.ControlClosed. A session socket connection closed, after its last request came.

{
	--- The connection, as `ControlRequest.connection` gave it.
	connection: number,
}

client.attached

Its handler gets a greed.ClientAttached. A client attached, e.g. greed FILE in a session that was running. Handlers run as that client.

{
	--- The client's id.
	client: number,
	--- The file or folder it asked to open, if any.
	path: string?,
	--- Whether it asked for a terminal, e.g. `greed ssh HOST --terminal`.
	terminal: boolean,
	--- Whether it asked for the project's greed shell, e.g. `greed --shell`.
	shell: boolean,
	--- Whether it came over `greed ssh`.
	remote: boolean,
}

client.detached

Its handler gets a greed.ClientDetached. A client went; the session goes on. Handlers run as that client, just before it’s gone.

{
	client: number,
}

client.paste

Its handler gets a greed.ClientPaste. Text pasted into the client from the system clipboard: a terminal’s paste, or a window’s paste keys (ctrl-shift-v, shift-insert, cmd-v). The core plugin puts it at the cursors.

{
	--- The client it was pasted into, which handlers run as.
	client: number,
	text: string,
}

buffer.opened

Its handler gets a greed.BufferChanged.

{
	buffer: Buffer,
	--- On "buffer.changed": the first and last line (0-based, as the text is
	--- now) of what changed since the last "buffer.changed" for the buffer.
	from_line: number?,
	to_line: number?,
}

buffer.saved

Its handler gets a greed.BufferChanged.

{
	buffer: Buffer,
	--- On "buffer.changed": the first and last line (0-based, as the text is
	--- now) of what changed since the last "buffer.changed" for the buffer.
	from_line: number?,
	to_line: number?,
}

buffer.closed

Its handler gets a greed.BufferClosed. A buffer was closed. Only its id is left.

{
	id: number,
}

view.closed

Its handler gets a greed.ViewClosed. A view was closed. Its handle no longer works, but its id can be compared with view:id().

{
	view: number,
}

view.resized

Its handler gets a greed.ViewResized. A view was drawn for a client with room for a different number of rows or columns of text than before. Handlers run as that client.

{
	client: number,
	view: View,
	rows: number,
	cols: number,
}

pane.opened

Its handler gets a greed.PaneOpened. A pane was opened, beside from.

{
	view: View,
	from: View,
}

view.scrolled

Its handler gets a greed.ViewScrolled. A view was drawn for a client starting at a different line than before. What a handler changes shows in the same frame, so a view can scroll another along with it. Handlers run as that client.

{
	client: number,
	view: View,
	--- The 0-based line now at the top.
	line: number,
}

selection.changed

Its handler gets a greed.SelectionChanged. A view’s selection changed for a client, or it shows another buffer, since the last frame: told once a frame however many changes there were, whatever made them (keys, the mouse, undo, a plugin or an agent). Handlers run as that client.

{
	client: number,
	view: View,
}

view.focused

Its handler gets a greed.ViewFocused. Another view has a client’s focus. from had it before; nil when it was closed. Handlers run as that client.

{
	client: number,
	view: View,
	from: View?,
	--- The focus was moved under the client rather than by it: what it had focused went out of sight by another client's doing (another tab or project shown, a pane closed), or it followed the others again. Its half-typed keys were dropped.
	moved: boolean,
}

ssh_agent.use

Its handler gets a greed.SshAgentUse. A program in a session greed ssh started asks to sign with one of your ssh keys, through the client relaying your agent. Answer with greed.ssh_agent.answer; with no answer, or no handler, it may not.

{
	--- The request, for `greed.ssh_agent.answer`.
	id: number,
	--- The client relaying your agent, which handlers run as.
	client: number,
	--- The machine that client is on, if known.
	host: string?,
}

mouse

Its handler gets a greed.MouseEvent. What the mouse did, and what was under it.

{
	--- The client whose mouse it was, which handlers run as.
	client: number,
	kind: "press" | "release" | "drag" | "move" | "scroll",
	--- For a press, release or drag.
	button: ("left" | "middle" | "right")?,
	--- For a scroll.
	dir: ("up" | "down" | "left" | "right")?,
	--- The screen cell, from the top left.
	col: number,
	row: number,
	ctrl: boolean,
	alt: boolean,
	shift: boolean,
	--- The view under it, if any.
	view: View?,
	--- The place in the view's buffer under it: the character there, or the
	--- end of the line past it. Over a mark's text, where the mark starts.
	pos: number?,
	--- The action of the mark whose text it's over, or of the status line segment (with no `view`), if that has one.
	action: string?,
	--- The cell in the view's text, from its top left, right of the gutter.
	x: number?,
	y: number?,
	--- The tab whose name it's over, in the tab line.
	tab: number?,
	--- On a floating view's border (with `view` set), which part: "top" (the title's), "bottom", "left", "right", or a corner like "bottom-right".
	border: ("top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right")?,
	--- On the line between a pane or panel (`view`) and its neighbor, the side of `view` it's on: "right" or "down" for panes, the side by the main view for panels. Dragging it resizes `view` with `resize`.
	edge: ("left" | "right" | "down")?,
}

option.changed

Its handler gets a greed.OptionChanged. An option was set, with greed.option.set or :set.

{
	name: string,
	--- Its value now, as the client it was set for has it.
	value: OptionValue,
	--- The client it was set for, when one got a value of its own.
	client: number?,
}

plugin.loaded

Its handler gets a greed.PluginLoaded. A plugin was loaded (or reloaded) and its entry file ran.

{
	name: string,
	--- Its folder, for plugins loaded from one.
	dir: string?,
}

file.changed

Its handler gets a greed.FileChanged. A file watched with greed.fs.watch was written, created or removed.

{
	path: string,
}

plugin.unloaded

Its handler gets a greed.PluginUnloaded. A plugin was unloaded, and everything it registered removed.

{
	name: string,
}

editor.started

Its handler gets nothing.

editor.quitting

Its handler gets nothing.

terminal.output

Its handler gets a greed.TerminalOutput. A terminal printed something; read it with terminal:screen().

{
	terminal: Terminal,
}

terminal.exited

Its handler gets a greed.TerminalExited. The program in a terminal ended.

{
	terminal: Terminal,
	code: number,
	--- Whether a signal ended the program, rather than its own exit.
	signaled: boolean,
}