Skip to main content

Introduction

Yazi provides a powerful Lua plugin API that allows you to extend and customize its functionality. Plugins can be used for:
  • Custom file previewers
  • File operations and automation
  • UI components and themes
  • Integration with external tools
  • Custom actions and keybindings

Lua Version

Yazi uses Lua 5.5 as of version 0.4.0 (upgraded from Lua 5.4). This upgrade brings performance improvements through external strings, reducing memory allocations.
Lua 5.5 introduces external strings for better memory efficiency. See #3633 for details.

API Namespaces

The plugin API is organized into several global namespaces:

Core APIs

  • ya - Core Yazi API for async operations, sync blocks, logging, and utilities
  • fs - Filesystem operations (copy, rename, read_dir, etc.)
  • ui - UI rendering components and helpers
  • ps - Publish/Subscribe messaging system
  • cx - Context API for accessing application state

Configuration APIs

  • rt - Runtime configuration (args, mgr, preview, tasks, etc.)
  • th - Theme colors and styling

Async Support

Yazi’s plugin system supports asynchronous operations through Lua coroutines:

Module-level Async

Plugins can use the @sync annotation to declare async entry points:

Runtime Async

For dynamic async operations, use ya.async():

Sync Blocks

Use ya.sync() to execute code in the main thread with access to the plugin context:

Plugin Types

Yazi supports several types of plugins:

Previewers

Generate file previews for the preview pane:

Preloaders

Load file metadata in the background:

Actions

Custom user actions triggered by keybindings:

Init Plugins

Run on startup from init.lua:

Error Handling

Most async APIs return (result, error) tuples:
Create custom errors:

Data Types

Common userdata types:
  • Url - File/directory URL (local or remote)
  • Path - Local filesystem path
  • File - File metadata and attributes
  • Cha - File characteristics (size, permissions, etc.)
  • Rect - Screen rectangle (x, y, w, h)
  • Id - Unique identifier

Best Practices

  1. Use async APIs - Most filesystem operations are async for better performance
  2. Handle errors - Always check error returns from async functions
  3. Cache data - Use ya.file_cache() for expensive operations
  4. Limit resources - Use options like limit in fs.read_dir() to avoid loading too much data
  5. Clean up - Drop file descriptors and handles when done using ya.drop()

Next Steps