1
0
Fork 0
mirror of https://github.com/LazyVim/LazyVim.git synced 2025-07-29 07:05:30 +02:00

feat(keymaps): enable toggling in quickfix list and location list ()

## Description

This PR addresses issue  by modifying the behavior of `<leader>xq`
and `<leader>xl` so that they toggle the quickfix and location lists
rather than simply opening them.

To prevent the full Lua error stack from being printed when no list
exists prior to using `copen` or `lopen`, I've wrapped the commands in
`pcall` and used `vim.notify` to alert the user in the same manner as
before.

## Related Issue(s)



## Screenshots


https://github.com/user-attachments/assets/b22b1861-e6e5-4d8a-967e-f760cca15719

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
This commit is contained in:
Zhou Fang 2025-02-15 16:27:01 +09:00 committed by GitHub
parent 98fca895e8
commit 32e575aa75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,8 +94,21 @@ map("n", "<leader>l", "<cmd>Lazy<cr>", { desc = "Lazy" })
-- new file
map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New File" })
map("n", "<leader>xl", "<cmd>lopen<cr>", { desc = "Location List" })
map("n", "<leader>xq", "<cmd>copen<cr>", { desc = "Quickfix List" })
-- location list
map("n", "<leader>xl", function()
local success, err = pcall(vim.fn.getloclist(0, { winid = 0 }).winid ~= 0 and vim.cmd.lclose or vim.cmd.lopen)
if not success and err then
vim.notify(err, vim.log.levels.ERROR)
end
end, { desc = "Location List" })
-- quickfix list
map("n", "<leader>xq", function()
local success, err = pcall(vim.fn.getqflist({ winid = 0 }).winid ~= 0 and vim.cmd.cclose or vim.cmd.copen)
if not success and err then
vim.notify(err, vim.log.levels.ERROR)
end
end, { desc = "Quickfix List" })
map("n", "[q", vim.cmd.cprev, { desc = "Previous Quickfix" })
map("n", "]q", vim.cmd.cnext, { desc = "Next Quickfix" })