Skip to main content
Explore practical plugin examples that demonstrate key features of the Fresh plugin API. Each example includes complete, working code you can adapt for your own plugins.

Hello World

A simple plugin demonstrating basic editor operations.
hello_world.ts
  • Buffer Queries: getActiveBufferId(), getBufferPath(), getBufferLength()
  • Text Insertion: insertText() for precise placement
  • Overlays: addOverlay() for visual highlights without modifying content
  • Namespaces: Group overlays for batch removal with clearNamespace()
  • Async/Await: Full Promise support for async operations

Async Process Demo

Demonstrates spawning external processes with async/await.
async_demo.ts
  • Process Spawning: spawnProcess(command, args, workdir)
  • Exit Codes: Check result.exit_code for success/failure
  • Output Handling: Access stdout and stderr from the result
  • Error Handling: Wrap in try/catch for robust error handling
  • Working Directory: Optional third parameter for process cwd

Virtual Buffer Demo

Create special buffers for displaying structured data.
virtual_buffer_demo.ts
  • Virtual Buffers: Create special buffers for structured data
  • Text Properties: Embed metadata in each line (file, line, column, etc.)
  • Custom Modes: Define buffer-specific keybindings
  • Panel Reuse: Use panelId to update existing panels
  • Navigation: Access properties with getTextPropertiesAtCursor()

Bookmarks Plugin

Complete bookmark management with overlays and prompts.
bookmarks.ts
  • State Management: Use Maps to store plugin state
  • Overlays: Visual markers for bookmarks
  • Prompts: Interactive selection with suggestions
  • Event Handlers: Respond to prompt confirmation
  • Split Awareness: Track which split a bookmark belongs to

Buffer Query Demo

Demonstrate buffer and viewport queries.
buffer_query_demo.ts
  • Buffer Info: getBufferInfo() for comprehensive buffer data
  • Cursor Queries: getPrimaryCursor(), getAllCursors()
  • Selection Info: Access selection ranges from cursor info
  • Multi-Cursor: Support for multiple cursors
  • Viewport: Query visible area dimensions and scroll position

Common Patterns

Highlighting Text Patterns

Running Tests and Parsing Output

File Watchers

Next Steps

Plugin Development

Complete guide to creating plugins

API Reference

Full API documentation

Plugin Overview

Learn about the plugin system

Getting Started

Install and manage plugins