Skip to main content
Learn how to create custom plugins to extend Yazi’s functionality using Lua.

Plugin Basics

Yazi plugins are written in Lua and follow a simple structure. Each plugin is a Lua module that returns a table with functions.

Minimal Plugin Example

Here’s the simplest possible plugin:
Call it from your keymap:

Plugin Structure

Module Pattern

All plugins follow this pattern:
The M table can contain:
  • Methods (functions)
  • State variables
  • Configuration options

Entry Points

Different plugin types have different entry points:

Step-by-Step Plugin Creation

Let’s create a plugin that counts files in the current directory.
1

Create the plugin file

Create ~/.config/yazi/plugins/filecount.lua:
2

Access current directory

Use the cx (context) global to access Yazi’s state:
3

Add filtering logic

Count different file types:
4

Bind to a key

Add to keymap.toml:

Accessing Yazi State

Yazi provides global objects to access its state:

cx - Context

The main state object:

rt - Runtime

Configuration and runtime settings:

th - Theme

Access theme colors and styles:

Using the Lua API

Yazi provides a rich API through the ya global:

Notifications

User Input

File Operations

Running Commands

Emitting Events

Plugin Configuration

Setup Function

Plugins can have a setup() function for initialization:
Call setup in init.lua:

Async Programming

For long-running operations, use async:

Error Handling

Best Practices

Always declare variables with local to avoid polluting the global namespace:
Always validate data before using it:
Don’t block the UI thread:
Always notify users of success or failure:

Debugging

Check Yazi logs

Logs are written to:
  • Linux/macOS: ~/.local/state/yazi/yazi.log
  • Windows: %APPDATA%\yazi\state\yazi.log

Next Steps

UI Plugins

Customize Yazi’s interface

Functional Plugins

Add new commands

Previewers

Create file previewers

Fetchers

Build metadata fetchers