Skip to main content
The Buffer API provides methods for working with editor buffers - the in-memory representation of text files and virtual content.

Buffer Queries

getActiveBufferId

Get the buffer ID of the focused editor pane.
number
The active buffer ID, or 0 if no buffer is active (rare edge case)
Example:

getBufferPath

Get the absolute file path for a buffer.
number
required
Target buffer ID
string
Absolute file path, or empty string for unsaved buffers or virtual buffers
Example:

getBufferLength

Get the total byte length of a buffer’s content.
number
required
Target buffer ID
number
Buffer length in bytes, or 0 if buffer doesn’t exist

isBufferModified

Check if a buffer has been modified since last save.
number
required
Target buffer ID
boolean
true if buffer has unsaved changes, false otherwise. Virtual buffers are never considered modified.

getBufferInfo

Get full information about a buffer.
number
required
Buffer ID to query
BufferInfo | null
Buffer information object, or null if buffer doesn’t exist
BufferInfo Type:

listBuffers

List all open buffers.
BufferInfo[]
Array of all open buffers
Example:

getBufferText

Get text from a buffer range.
number
required
Buffer ID
number
required
Start byte offset
number
required
End byte offset
Promise<string>
Text content from the specified range
Example:

findBufferByPath

Find a buffer ID by its file path.
string
required
File path to search for
number
Buffer ID if found, or 0 if not found

Cursor Operations

getCursorPosition

Get the byte offset of the primary cursor.
number
Byte offset of cursor, or 0 if no cursor. For multi-cursor, use getAllCursors.
This returns a byte offset, not a character index. Use this with insertText and deleteRange.

getCursorLine

Get the line number of the primary cursor (1-indexed).
number
Line number starting at 1. Returns 1 if no cursor exists.

getPrimaryCursor

Get primary cursor with selection info.
CursorInfo | null
Cursor information including position and selection, or null if no cursor
CursorInfo Type:

getAllCursors

Get all cursors (for multi-cursor support).
CursorInfo[]
Array of all cursors with position and selection info

getAllCursorPositions

Get byte offsets of all cursors.
number[]
Array of cursor positions. Empty if no cursors. Primary cursor is typically first.

setBufferCursor

Set cursor position in a buffer (also scrolls viewport to show cursor).
number
required
ID of the buffer
number
required
Byte offset position for the cursor
boolean
true if successful

Buffer Mutations

insertText

Insert text at a byte position in a buffer.
number
required
Target buffer ID
number
required
Byte offset where text will be inserted (must be at char boundary)
string
required
UTF-8 text to insert
boolean
true if command was sent successfully. Operation is asynchronous.
Text is inserted before the byte at position. Position must be valid (0 to buffer length). Insertion shifts all text after position.
Example:

insertAtCursor

Insert text at the current cursor position in the active buffer.
string
required
The text to insert
boolean
true if successful
Example:

deleteRange

Delete a byte range from a buffer.
number
required
Target buffer ID
number
required
Start byte offset (inclusive)
number
required
End byte offset (exclusive)
boolean
true if command was sent successfully. Operation is asynchronous.
Deletes bytes from start (inclusive) to end (exclusive). Both positions must be at valid UTF-8 char boundaries.

Buffer Display

showBuffer

Switch the current split to display a buffer.
number
required
ID of the buffer to show
boolean
true if successful

closeBuffer

Close a buffer and remove it from all splits.
number
required
ID of the buffer to close
boolean
true if successful

openFile

Open a file in the editor, optionally at a specific location.
string
required
File path to open
number
required
Line number to jump to (0 for no jump)
number
required
Column number to jump to (0 for no jump)
boolean
true if successful
Example:

openFileInSplit

Open a file in a specific split pane.
number
required
The split ID to open the file in
string
required
File path to open
number
required
Line number to jump to (0 for no jump)
number
required
Column number to jump to (0 for no jump)
boolean
true if successful

Configuration

getConfig

Get the current editor configuration.
unknown
Merged configuration (user config file + compiled-in defaults). This is the runtime config that the editor is actually using.

getUserConfig

Get the user’s configuration (only explicitly set values).
unknown
Configuration from the user’s config file only. Fields not present here are using default values.

getConfigDir

Get the absolute path to the user config directory.
string
Absolute path to config directory (e.g., ~/.config/fresh/ on Linux)

reloadConfig

Reload configuration from file.
After a plugin saves config changes to the config file, call this to reload the editor’s in-memory configuration.

Diagnostics

getAllDiagnostics

Get all LSP diagnostics across all files.
TsDiagnostic[]
Array of all LSP diagnostics
TsDiagnostic Type:

Actions

executeAction

Execute a built-in editor action by name.
string
required
Action name (e.g., “move_word_right”, “move_line_end”)
boolean
true if successful
Example:

executeActions

Execute multiple actions in sequence, each with an optional repeat count.
ActionSpecJs[]
required
Array of action specifications
boolean
true if successful
ActionSpecJs Type:
Example:

Clipboard

setClipboard

Copy text to the system clipboard.
string
required
Text to copy to clipboard
Copies the provided text to both the internal and system clipboard. Uses OSC 52 and arboard for cross-platform compatibility. Example: