From 0932413fc93ddeec675c20c03e1c312a09718e72 Mon Sep 17 00:00:00 2001 From: Aotrix Date: Mon, 3 Mar 2025 03:15:11 +0100 Subject: quickfix works great! --- init.lua | 1 + lua/aotrix/quickfix.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ lua/aotrix/remap.lua | 7 ------- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 lua/aotrix/quickfix.lua diff --git a/init.lua b/init.lua index df6bc5f..9dd82ab 100644 --- a/init.lua +++ b/init.lua @@ -11,4 +11,5 @@ vim.opt.rtp:prepend(lazypath) require('aotrix.set') require('aotrix.remap') +require('aotrix.quickfix') require('lazy').setup('aotrix.plugins') diff --git a/lua/aotrix/quickfix.lua b/lua/aotrix/quickfix.lua new file mode 100644 index 0000000..14195b4 --- /dev/null +++ b/lua/aotrix/quickfix.lua @@ -0,0 +1,52 @@ +local quickfix_is_open = false; +vim.api.nvim_create_autocmd('BufWinEnter', { + pattern = 'quickfix', + callback = function(args) quickfix_is_open = true end +}) +vim.api.nvim_create_autocmd('BufWinLeave', { + pattern = 'quickfix', + callback = function(args) quickfix_is_open = false end +}) +local nb_elements_quickfix = 0; +vim.api.nvim_create_autocmd('DiagnosticChanged', { + callback = function(args) + nb_elements_quickfix = #vim.diagnostic.get() + if quickfix_is_open then + if nb_elements_quickfix == 0 then + quickfix_is_open = false + vim.cmd.cclose() + else + vim.diagnostic.setqflist() + end + end + end +}) +vim.keymap.set("n", "q", function() + if #vim.diagnostic.get() > 0 then + if quickfix_is_open then + vim.cmd.cclose() + quickfix_is_open = false + else + vim.diagnostic.setqflist() + vim.cmd.cfirst() + end + end +end) +vim.keymap.set("n", "", function() + if #vim.diagnostic.get() > 0 and quickfix_is_open then + if #vim.diagnostic.get() == 1 then + vim.cmd.cfirst() + else + vim.diagnostic.goto_next({float = false}) + end + end +end) +vim.keymap.set("n", "", function() + if #vim.diagnostic.get() > 0 and quickfix_is_open then + if #vim.diagnostic.get() == 1 then + vim.cmd.cfirst() + else + vim.diagnostic.goto_prev({float = false}) + end + end +end) diff --git a/lua/aotrix/remap.lua b/lua/aotrix/remap.lua index c5ff3fe..72a854b 100644 --- a/lua/aotrix/remap.lua +++ b/lua/aotrix/remap.lua @@ -16,10 +16,3 @@ vim.keymap.set("n", "Y", [["+Y]]) -- Remove because it is not fast enough vim.keymap.set({'n', 'i', 'v'}, '', '') - --- Quickfix -vim.keymap.set("n", "q", function() vim.diagnostic.setqflist() end) -vim.keymap.set("n", "", ":cnext") -vim.keymap.set("n", "", ":cprev") -vim.keymap.set("n", "", ":cfirst") -vim.keymap.set("n", "", ":clast") -- cgit v1.2.3