From 11a44f9fc508effad7334292951a18264e0a9d15 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Sun, 12 Jul 2026 00:08:33 -0400 Subject: [PATCH] feat(plugins): improve yazi toggle functionality to handle existing instances gracefully --- lua/plugins/yazi.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/plugins/yazi.lua b/lua/plugins/yazi.lua index 8a4af99..f4d3e24 100644 --- a/lua/plugins/yazi.lua +++ b/lua/plugins/yazi.lua @@ -29,7 +29,20 @@ return { { "", mode = { "n", "v", "t" }, - "Yazi toggle", + function() + -- true toggle: if a yazi window is already open, quit it instead + -- of nesting a second instance (yazi.nvim's toggle() always spawns) + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].filetype == "yazi" then + -- send `q` to the yazi process so it exits gracefully and + -- saves its state for the next resume + vim.api.nvim_chan_send(vim.bo[buf].channel, "q") + return + end + end + vim.cmd "Yazi toggle" + end, desc = "Toggle yazi (resume last session)", }, },