Skip to content

Commit e71ee85

Browse files
committed
feat(tools): add qflist_to_buf function and QFlistToBuf command to display quickfix list in a new buffer
1 parent 52c849f commit e71ee85

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lua/kide/tools/init.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,35 @@ M.base64_std_to_url_safe = function(msg)
267267
return msg
268268
end
269269

270+
-- 创建一个新的缓冲区并显示 qflist 的内容
271+
local function qflist_to_buf()
272+
-- 获取当前的 qflist
273+
local qflist = vim.fn.getqflist()
274+
275+
-- 创建一个新的缓冲区
276+
local buf = vim.api.nvim_create_buf(true, false)
277+
278+
-- 将 qflist 的内容写入缓冲区
279+
local lines = {}
280+
for _, item in ipairs(qflist) do
281+
local text = item.text or ""
282+
table.insert(lines, text)
283+
end
284+
285+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
286+
287+
-- 打开新窗口并显示缓冲区
288+
vim.api.nvim_command("sbuffer " .. buf)
289+
end
290+
270291
M.setup = function()
271292
vim.api.nvim_create_user_command("CamelCase", function(o)
272293
M.camel_case_start(o.range, o.line1, o.line2)
273294
end, { range = 0, nargs = 0 })
295+
296+
vim.api.nvim_create_user_command("QFlistToBuf", function(_)
297+
qflist_to_buf()
298+
end, { range = 0, nargs = 0 })
274299
end
275300

276301
return M

0 commit comments

Comments
 (0)