summaryrefslogtreecommitdiff
path: root/lua/aotrix/quickfix.lua
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-03 03:15:11 +0100
committerAotrix <[email protected]>2025-03-03 03:15:11 +0100
commit0932413fc93ddeec675c20c03e1c312a09718e72 (patch)
tree07d789b864386ce02e9a0f3e7d3cbf77445d4ff5 /lua/aotrix/quickfix.lua
parent06014c13ca016e14de9d1ba52ef8eaa019fc9581 (diff)
quickfix works great!
Diffstat (limited to 'lua/aotrix/quickfix.lua')
-rw-r--r--lua/aotrix/quickfix.lua52
1 files changed, 52 insertions, 0 deletions
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", "<leader>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", "<M-j>", 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", "<M-k>", 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)