Core Concepts
Buffers
A buffer holds text content and may or may not be associated with a file. Each buffer has a unique numeric ID that persists for the editor session. Buffers track their content, modification state, cursor positions, and path. All text operations (insert, delete, read) use byte offsets, not character indices.Splits
A split is a viewport pane that displays a buffer. The editor can have multiple splits arranged in a tree layout. Each split shows exactly one buffer, but the same buffer can be displayed in multiple splits. Use split IDs to control which pane displays which buffer.Virtual Buffers
Special buffers created by plugins to display structured data like search results, diagnostics, or git logs. Virtual buffers support text properties (metadata attached to text ranges) that plugins can query when the user selects a line. Unlike normal buffers, virtual buffers are typically read-only and not backed by files.Text Properties
Metadata attached to text ranges in virtual buffers. Each entry has text content and a properties object with arbitrary key-value pairs. UsegetTextPropertiesAtCursor to retrieve properties at the cursor position (e.g., to get file/line info for “go to”).
Overlays
Visual decorations applied to buffer text without modifying content. Overlays can change text color and add underlines. Use overlay IDs to manage them; prefix IDs enable batch removal (e.g., “lint:” prefix for all linter highlights).Modes
Keybinding contexts that determine how keypresses are interpreted. Each buffer has a mode (e.g., “normal”, “insert”, “special”). Custom modes can inherit from parents and define buffer-local keybindings. Virtual buffers typically use custom modes.Quick Start
Creating Your First Plugin
Plugins are TypeScript files that interact with the editor through the globaleditor object:
Responding to Events
Plugins can subscribe to editor events using theon method:
Creating a Virtual Buffer
Virtual buffers are useful for displaying structured data:API Categories
The Fresh Plugin API is organized into several categories:Buffer API
Query and manipulate buffer content, cursors, and metadata
Events API
Subscribe to editor events and hooks
Filesystem API
Read, write, and manipulate files and directories
Overlays API
Add visual decorations to buffer text
Virtual Buffers
Create and manage virtual buffers for structured data
Status & Logging
Display status messages and log plugin activity
Internationalization
Add multi-language support to your plugin
Utilities
Reusable utilities for common plugin patterns
Common Types
The API uses several TypeScript types that are shared across methods:BufferInfo
CursorInfo
TextPropertyEntry
SpawnResult
Best Practices
Use TypeScript types
Use TypeScript types
Reference
types/fresh.d.ts for autocomplete and type checking in your plugin development.Prefix overlay IDs
Prefix overlay IDs
Use
"myplugin:something" format for easy batch removal of overlays.Handle errors
Handle errors
Wrap async operations in try/catch blocks to provide graceful error handling.
Be efficient
Be efficient
Use batched events like
lines_changed instead of per-keystroke handlers to avoid performance issues.Test incrementally
Test incrementally
Use
editor.debug() to log values during development and troubleshooting.Support i18n
Support i18n
Add
.i18n.json files to make your plugin accessible to international users.Next Steps
Explore the Buffer API
Learn how to query and manipulate buffer content in the Buffer API reference.
Subscribe to Events
Discover available events in the Events API documentation.
Create Virtual Buffers
Build rich UI elements with Virtual Buffers.
Add Internationalization
Make your plugin multilingual with i18n support.