Tips
These tips require prior knowledge of the Yazi configuration file.
If you are using Yazi for the first time, please read our configuration and plugins documentation first.
Full border
Moved to: https://github.com/yazi-rs/plugins/tree/main/full-border.yazi
Dropping to the shell
Add this keybinding to your keymap.toml
:
- Unix
- Windows
[[manager.prepend_keymap]]
on = "!"
run = 'shell "$SHELL" --block'
desc = "Open shell here"
[[manager.prepend_keymap]]
on = "!"
run = 'shell "powershell.exe" --block'
desc = "Open PowerShell here"
Close input by once Esc press
You can change the Esc of input component from the default escape
to close
command, in your keymap.toml
:
[[input.prepend_keymap]]
on = "<Esc>"
run = "close"
desc = "Cancel input"
to exiting input directly, without entering Vi mode, making it behave like a regular input box.
Smart enter: open
files or enter
directories all in one key
Moved to: https://github.com/yazi-rs/plugins/tree/main/smart-enter.yazi
Smart paste: paste
files without entering the directory
Save these lines as ~/.config/yazi/plugins/smart-paste.yazi/init.lua
:
--- @sync entry
return {
entry = function()
local h = cx.active.current.hovered
if h and h.cha.is_dir then
ya.manager_emit("enter", {})
ya.manager_emit("paste", {})
ya.manager_emit("leave", {})
else
ya.manager_emit("paste", {})
end
end,
}
Then bind it for p key, in your keymap.toml
:
[[manager.prepend_keymap]]
on = "p"
run = "plugin smart-paste"
desc = "Paste into the hovered directory or CWD"
Demonstrate smart paste
Smart tab: create a tab and enter the hovered directory
Save these lines as ~/.config/yazi/plugins/smart-tab.yazi/init.lua
:
--- @sync entry
return {
entry = function()
local h = cx.active.current.hovered
ya.manager_emit("tab_create", h and h.cha.is_dir and { h.url } or { current = true })
end,
}
Then bind it for t key, in your keymap.toml
:
[[manager.prepend_keymap]]
on = "t"
run = "plugin smart-tab"
desc = "Create a tab and enter the hovered directory"
Folder-specific rules
You can subscribe to directory change events through the cd
event provided by DDS, and then do any action you want, such as setting different sorting methods for specific directories.
The following code demonstrates making the Downloads
directory to sort by modification time, while others are sorted alphabetically. Save these lines as ~/.config/yazi/plugins/folder-rules.yazi/init.lua
:
local function setup()
ps.sub("cd", function()
local cwd = cx.active.current.cwd
if cwd:ends_with("Downloads") then
ya.manager_emit("sort", { "mtime", reverse = true, dir_first = false })
else
ya.manager_emit("sort", { "alphabetical", reverse = false, dir_first = true })
end
end)
end
return { setup = setup }
Then enable it in your ~/.config/yazi/init.lua
:
require("folder-rules"):setup()
Credits to @tianze0926 for sharing it.
Folder-specific previewer and preloader
In addition to the mime
rules, Yazi also has name
rules for pre{viewer,loader}, which accept a glob expression.
This allows for flexible creation of different pre{viewer,loader} rules for various directories.
For example, you can use the noop
builtin preloader for a remote mount point like /remote
, disabling preloads in that directory:
# yazi.toml
[[plugin.prepend_preloaders]]
name = "/remote/**"
run = "noop"
Drag and drop via dragon
Original post: https://github.com/sxyazi/yazi/discussions/327
[[manager.prepend_keymap]]
on = "<C-n>"
run = '''
shell 'dragon -x -i -T "$1"'
'''
Copy selected files to the system clipboard while yanking
Yazi allows multiple commands to be bound to a single key, so you can set y to not only do the yank
but also run a shell script:
[[manager.prepend_keymap]]
on = "y"
run = [ '''
shell 'echo "$@" | xclip -i -selection clipboard -t text/uri-list'
''', "yank" ]
The above is available on X11, there is also a Wayland version (Thanks @hurutparittya for sharing this in Yazi's discord server):
[[manager.prepend_keymap]]
on = "y"
run = [ '''
shell 'for path in "$@"; do echo "file://$path"; done | wl-copy -t text/uri-list'
''', "yank" ]
cd
back to the root of the current Git repository
[[manager.prepend_keymap]]
on = [ "g", "r" ]
run = '''
shell 'ya emit cd "$(git rev-parse --show-toplevel)"'
'''
Credits to @aidanzhai for sharing it in Yazi's telegram group.
Unix: Add subtitle to the running MPV
Add these lines to your ~/.config/yazi/yazi.toml
:
[[opener.add-sub]]
run = ''' echo sub-add "'$0'" | socat - /tmp/mpv.sock '''
desc = "Add sub to MPV"
[[open.prepend_rules]]
name = "*.{ass,srt,ssa,sty,sup,vtt}"
use = [ "add-sub", "edit" ]
To make it work, make sure you've:
- Installed
socat
and can be found in your$PATH
- Enabled and configured the ipc socket to
/tmp/mpv.sock
, that is, include:in yourinput-ipc-server=/tmp/mpv.sock
~/.config/mpv/mpv.conf
. See the documentation of--input-ipc-server
for more info.
Maximize preview pane
Moved to: https://github.com/yazi-rs/plugins/tree/main/max-preview.yazi
Hide preview pane
Moved to: https://github.com/yazi-rs/plugins/tree/main/hide-preview.yazi
File navigation wraparound
Save these lines as ~/.config/yazi/plugins/arrow.yazi/init.lua
:
--- @sync entry
return {
entry = function(_, job)
local current = cx.active.current
local new = (current.cursor + job.args[1]) % #current.files
ya.manager_emit("arrow", { new - current.cursor })
end,
}
Then bind it for k and j key, in your keymap.toml
:
[[manager.prepend_keymap]]
on = "k"
run = "plugin arrow --args=-1"
[[manager.prepend_keymap]]
on = "j"
run = "plugin arrow --args=1"
Navigation in the parent directory without leaving the CWD
Save these lines as ~/.config/yazi/plugins/parent-arrow.yazi/init.lua
:
- Classic
- Skip files
--- @sync entry
local function entry(_, job)
local parent = cx.active.parent
if not parent then return end
local target = parent.files[parent.cursor + 1 + job.args[1]]
if target and target.cha.is_dir then
ya.manager_emit("cd", { target.url })
end
end
return { entry = entry }
--- @sync entry
local function entry(_, job)
local parent = cx.active.parent
if not parent then return end
local offset = tonumber(job.args[1])
if not offset then return ya.err(job.args[1], 'is not a number') end
local start = parent.cursor + 1 + offset
local end_ = offset < 0 and 1 or #parent.files
local step = offset < 0 and -1 or 1
for i = start, end_, step do
local target = parent.files[i]
if target and target.cha.is_dir then
return ya.manager_emit("cd", { target.url })
end
end
end
return { entry = entry }
Then bind it for K and J key, in your keymap.toml
:
[[manager.prepend_keymap]]
on = "K"
run = "plugin parent-arrow --args=-1"
[[manager.prepend_keymap]]
on = "J"
run = "plugin parent-arrow --args=1"
No status bar
Moved to: https://github.com/yazi-rs/plugins/tree/main/no-status.yazi
Show symlink in status bar
Copy the Status:name()
method only to your ~/.config/yazi/init.lua
, and apply the following patch:
@@ -65,7 +65,11 @@ function Status:name()
return ui.Line {}
end
- return ui.Line(" " .. h.name)
+ local linked = ""
+ if h.link_to ~= nil then
+ linked = " -> " .. tostring(h.link_to)
+ end
+ return ui.Line(" " .. h.name .. linked)
end
Show user/group of files in status bar
Add the following code to your ~/.config/yazi/init.lua
:
Status:children_add(function()
local h = cx.active.current.hovered
if h == nil or ya.target_family() ~= "unix" then
return ""
end
return ui.Line {
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
":",
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
" ",
}
end, 500, Status.RIGHT)
Show username and hostname in header
Add the following code to your ~/.config/yazi/init.lua
:
Header:children_add(function()
if ya.target_family() ~= "unix" then
return ""
end
return ui.Span(ya.user_name() .. "@" .. ya.host_name() .. ":"):fg("blue")
end, 500, Header.LEFT)
macOS: Preview files with the system Quick Look
[[manager.prepend_keymap]]
on = "<C-p>"
run = '''
shell 'qlmanage -p "$@"'
'''
Credits to @UncleGravity for sharing it in Yazi's discord server.
Specify a different editor for bulk renaming
For bulk renaming, Yazi finds the first matching opener in your [open]
rules with:
Value | |
---|---|
block | true |
name | "bulk-rename.txt" |
mime | "text/plain" |
to use as the editor for editing the file list.
By default, this matches your editor used for opening normal text files, if you want to use an editor different from that:
# ~/.config/yazi/yazi.toml
[[opener.bulk-rename]]
run = 'hx "$@"'
block = true
[[open.prepend_rules]]
name = "bulk-rename.txt"
use = "bulk-rename"
File tree picker in Helix with Zellij
Yazi can be used as a file picker to browse and open file(s) in your current Helix instance (running in a Zellij session).
Add a keymap to your Helix config, for example Ctrl + y:
# ~/.config/helix/config.toml
[keys.normal]
C-y = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh open"
Or if you also want to support splitting the pane, you can add more keymaps:
# ~/.config/helix/config.toml
[keys.normal.C-y]
# Open the file(s) in the current window
y = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh open"
# Open the file(s) in a vertical pane
v = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh vsplit"
# Open the file(s) in a horizontal pane
h = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh hsplit"
Then save the following script as ~/.config/helix/yazi-picker.sh
:
#!/usr/bin/env bash
paths=$(yazi --chooser-file=/dev/stdout | while read -r; do printf "%q " "$REPLY"; done)
if [[ -n "$paths" ]]; then
zellij action toggle-floating-panes
zellij action write 27 # send <Escape> key
zellij action write-chars ":$1 $paths"
zellij action write 13 # send <Enter> key
else
zellij action toggle-floating-panes
fi
Note: this uses a floating window, but you should also be able to open a new pane to the side, or in place. Review the Zellij documentation for more info.
Original post: https://github.com/zellij-org/zellij/issues/3018#issuecomment-2086166900, credits to @rockboynton, @postsolar and @TheAwiteb for sharing and polishing it!
Demonstrate Helix+Zellij+Yazi workflow
Email selected files using Thunderbird
To send selected files using Thunderbird, with a keybinding Ctrl + e:
# ~/.config/yazi/keymap.toml
[[manager.prepend_keymap]]
on = "<C-e>"
run = '''
shell '
paths=$(for p in "$@"; do echo "$p"; done | paste -s -d,)
quoted="'\'$paths\''"
thunderbird -compose "attachment=$quoted"
'
'''
Make Yazi even faster than fast
While Yazi is already fast, there is still plenty of room for optimization for specific users or under certain conditions:
- For users who don't need image previews at all, disabling the default
image
previewer and preloader will make Yazi faster by reducing the I/O read file and CPU decode image consumption. - For users managing network files, it's recommended to disable all previewers and preloaders since previewing and preloading these files means they need to be downloaded locally.
- For low-spec devices like Raspberry Pi, reducing the concurrency will make Yazi faster since the default configuration is optimized for PCs, and high concurrency on these low-spec devices may have the opposite effect.
- For users who don't need accurate mime-type,
mime-ext.yazi
may be useful, as it simply returns mime-type based on file extensions, while Yazi defaults to obtaining mime-type based on file content for accuracy. Mime-type is used for matching opening, previewing, rendering rules. Encourage users to choose an appropriatemime
plugin based on their needs, which is why we decided to open it up to plugin developers. - For high-performance terminal emulators, lowering the
image_delay
option or setting it to 0 can reduce image preview latency.