Close fugitive panels more easily

TL;DR: If you hate having to close fugitive.vim panels with :q<CR> or gq, there is a solution.

Despite using lazygit and even the git commands directly on the command line very often, I still use fugitive.vim a lot for different reasons.

I have tried the neogit plugin and even some built-in telescope pickers, but nothing has "clicked" for me as well as my old fugitive tricks.

One of the things that annoyed me was needing more than one keystroke to close the fugitive panels.

After some investigation, I found out a solution that seems to be working well. I've added an autocommand that remaps q to <CMD>gq<CR> but only for buffers whose FileType is either fugitive or fugitiveblame, the two types that fugitive.vim creates.

Here's my fugitive.vim config for lazy.nvim, including my beloved keymaps:

return {
    "tpope/vim-fugitive",
    lazy = false,
    keys = {
        { "<leader>gg", ":Git<cr>", desc = "Git status" },
        { "<leader>gb", ":Git blame<cr>", desc = "Git blame" },
        { "<leader>gM", ":Git mergetool<cr>", desc = "Git mergetool" },
        { "<leader>gl", ":Git log --oneline<cr>", desc = "Git log" },
        { "<leader>gL", ":Git log --oneline %<cr>", desc = "Git log current file" },
    },
    config = function()
        -- whenever you open a markdown file, enable line wrapping
        vim.api.nvim_create_autocmd("FileType", {
            pattern = { "fugitive", "fugitiveblame" },
            callback = function()
                -- nmap <buffer> q gq
                vim.keymap.set("n", "q", "<cmd>q<cr>", { buffer = true })
            end,
        })
    end,
}