Skip to content

Commit 9d3754b

Browse files
committed
feat: open yazi tabs for the files in the quickfix list
Issue ===== The quickfix list is a versatile tool in neovim, and it can be used for many different workflows. yazi.nvim can send files from yazi to the quickfix list, but when this is done, yazi is closed and the context is lost. When doing project wide work both in yazi and neovim, it's difficult because of this. Solution ======== Allow opening yazi tabs for the files in the quickfix list. This only works if the user has enabled the `open_multiple_tabs` setting. Otherwise the first quickfix file is selected. When the quickfix list is open and focused, opening yazi will now open (probably) 9 of the first files as yazi tabs. The limitation is in place because yazi can open up to 9 tabs at a time.
1 parent 10344e7 commit 9d3754b

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ return {
222222
-- }
223223
open_for_directories = false,
224224

225-
-- open visible splits as yazi tabs for easy navigation. Requires a yazi
226-
-- version more recent than 2024-08-11
225+
-- open visible splits and quickfix items as yazi tabs for easy navigation
227226
-- https://github.com/mikavilpas/yazi.nvim/pull/359
228227
open_multiple_tabs = false,
229228

integration-tests/cypress/e2e/opening-files.cy.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,42 @@ describe("opening files", () => {
218218
})
219219
})
220220

221+
it("can open yazi with the files in the quickfix list", () => {
222+
cy.startNeovim({
223+
filename: "file2.txt",
224+
startupScriptModifications: [
225+
"modify_yazi_config_and_open_multiple_files.lua",
226+
],
227+
}).then((nvim) => {
228+
cy.contains("Hello")
229+
230+
// add some files to the quickfix list
231+
nvim.runLuaCode({
232+
luaCode: `vim.fn.setqflist({{filename = "file2.txt"}, {filename = "file3.txt"}})`,
233+
})
234+
235+
// show the quickfix list
236+
nvim.runLuaCode({ luaCode: `vim.api.nvim_command('copen')` })
237+
cy.contains("file3.txt||")
238+
239+
// focus the quickfix list
240+
nvim.runLuaCode({ luaCode: `vim.api.nvim_command('wincmd j')` })
241+
242+
// open yazi. It should open two tabs, one for each file in the quickfix
243+
// list
244+
cy.typeIntoTerminal("{upArrow}")
245+
cy.contains("NOR")
246+
247+
isFileSelectedInYazi("file2.txt" satisfies MyTestDirectoryFile)
248+
isFileNotSelectedInYazi("file3.txt" satisfies MyTestDirectoryFile)
249+
250+
// switch to the next yazi tab. This should select the other file
251+
cy.typeIntoTerminal("]")
252+
isFileNotSelectedInYazi("file2.txt" satisfies MyTestDirectoryFile)
253+
isFileSelectedInYazi("file3.txt" satisfies MyTestDirectoryFile)
254+
})
255+
})
256+
221257
describe("bulk renaming", () => {
222258
it("can bulk rename files", () => {
223259
cy.startNeovim().then(() => {

lua/yazi/utils.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,30 @@ end
149149
---@param path string?
150150
function M.selected_file_paths(path)
151151
local selected_file_path = M.selected_file_path(path)
152+
153+
local is_quickfix_window_selected = vim.api.nvim_get_option_value(
154+
"buftype",
155+
{ buf = 0 }
156+
) == "quickfix"
157+
if is_quickfix_window_selected then
158+
-- get the paths of the files in the quickfix window
159+
local qflist = vim.fn.getqflist()
160+
161+
---@type Path[]
162+
local filenames = {}
163+
for _, entry in ipairs(qflist) do
164+
if entry.bufnr and entry.bufnr > 0 then
165+
local filename = vim.api.nvim_buf_get_name(entry.bufnr)
166+
local new_path = plenary_path:new(filename)
167+
table.insert(filenames, new_path)
168+
end
169+
end
170+
171+
return filenames
172+
end
173+
152174
---@type Path[]
153175
local paths = { selected_file_path }
154-
155176
for _, buffer in ipairs(M.get_visible_open_buffers()) do
156177
-- NOTE: yazi can only display up to 9 paths, and it's an error to give any
157178
-- more

0 commit comments

Comments
 (0)