diff --git a/.config/nvim/lua/user/which_key.lua b/.config/nvim/lua/user/which_key.lua index 43fde9b..146796b 100644 --- a/.config/nvim/lua/user/which_key.lua +++ b/.config/nvim/lua/user/which_key.lua @@ -3,6 +3,26 @@ if not status_ok then return end +local toggle_gitsigns_blame = function() + local function is_filetype_open(filetype) + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].filetype == filetype then + return buf + end + end + return nil + end + + -- check if gitsigns-blame buffer is open + local bufnr = is_filetype_open("gitsigns-blame") + + if bufnr then + vim.api.nvim_buf_delete(bufnr, { force = false }) + else + vim.cmd("Gitsigns blame") + end +end + which_key.setup({ plugins = { marks = false, -- shows a list of your marks on ' and ` @@ -46,7 +66,7 @@ which_key.setup({ end, show_help = true, -- show help message on the command line when the popup is visible show_keys = true, -- show the currently pressed key and its label as a message in the command line - triggers = { }, + triggers = {}, -- disable the WhichKey popup for certain buf types and file types. -- Disabled by default for Telescope disable = { @@ -57,10 +77,10 @@ which_key.setup({ which_key.add({ { "", group = "Hotkeys" }, - { "?", ":WhichKey ", desc = "Show keybindings" }, - { "o", ":Oil --float ", desc = "Oil nvim toggle" }, - { "e", ":Neotree toggle position=current ", desc = "File tree toggle" }, - { "F", ":lua vim.lsp.buf.format() ", desc = "Format file" }, + { "?", ":WhichKey ", desc = "Show keybindings" }, + { "o", ":Oil --float ", desc = "Oil nvim toggle" }, + { "e", ":Neotree toggle position=current ", desc = "File tree toggle" }, + { "F", ":lua vim.lsp.buf.format() ", desc = "Format file" }, }) which_key.add({ @@ -68,7 +88,16 @@ which_key.add({ { "ff", "lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({ previewer = false }))", desc = "Find file" }, { "fw", "lua require'telescope.builtin'.live_grep()", desc = "Grep file" }, { "fb", "lua require'telescope.builtin'.buffers()", desc = "Find buffer" }, - { "fh", "lua require'telescope.builtin'.resume()", desc = "Resume last search" }, + { "fh", "lua require'telescope.builtin'.resume()", desc = "Resume last search" }, +}) + +which_key.add({ + { "g", group = "Git" }, + { "gb", toggle_gitsigns_blame, desc = "Toggle git blame view" }, +}) + +which_key.add({ + { "z", ":ZenMode", desc = "Zen mode toggle" }, }) which_key.add({ @@ -92,8 +121,8 @@ which_key.add({ which_key.add({ { "t", group = "Tabs" }, - { "tn", "tabnew", desc = "New tab" }, - { "tq", "tabclose", desc = "Close tab" }, + { "tn", "tabnew", desc = "New tab" }, + { "tq", "tabclose", desc = "Close tab" }, }) which_key.add({