local which_key = require('which-key') local icons = require('lib.icons') local setup = { plugins = { marks = true, registers = true, spelling = { enabled = true, suggestions = 30, }, presets = { operators = true, motions = true, text_objects = true, windows = true, nav = true, z = true, g = true, }, }, key_labels = { [''] = icons.ui.Rocket, [''] = '', [''] = '', }, icons = { breadcrumb = icons.ui.ArrowOpen, separator = icons.ui.Arrow, group = '', }, popup_mappings = { scroll_down = '', scroll_up = '', }, window = { border = 'shadow', position = 'bottom', margin = { 0, 0, 0, 0 }, padding = { 1, 2, 1, 2 }, winblend = 10, }, layout = { height = { min = 4, max = 24 }, width = { min = 20, max = 50 }, spacing = 3, align = 'center', }, ignore_missing = false, hidden = { '', '', '', '', '^:', '^ ', '^call ', '^lua ' }, show_help = true, show_keys = true, triggers = 'auto', triggers_nowait = { -- marks '`', "'", 'g`', "g'", -- registers '"', '', -- spelling 'z=', }, triggers_blacklist = { i = { 'j', 'j' }, v = { 'j', 'j' }, }, } local i = { [' '] = 'Whitespace', ['"'] = 'Balanced "', ["'"] = "Balanced '", ['`'] = 'Balanced `', ['('] = 'Balanced (', [')'] = 'Balanced ) including white-space', ['>'] = 'Balanced > including white-space', [''] = 'Balanced <', [']'] = 'Balanced ] including white-space', ['['] = 'Balanced [', ['}'] = 'Balanced } including white-space', ['{'] = 'Balanced {', ['?'] = 'User Prompt', _ = 'Underscore', a = 'Argument', b = 'Balanced ), ], }', c = 'Class', f = 'Function', o = 'Block, conditional, loop', q = 'Quote `, ", \'', t = 'Tag', } local a = vim.deepcopy(i) for k, v in pairs(a) do a[k] = v:gsub(' including.*', '') end local ic = vim.deepcopy(i) local ac = vim.deepcopy(a) for key, name in pairs({ n = 'Next', l = 'Last' }) do i[key] = vim.tbl_extend('force', { name = 'Inside ' .. name .. ' textobject' }, ic) a[key] = vim.tbl_extend('force', { name = 'Around ' .. name .. ' textobject' }, ac) end local opts = { mode = 'n', prefix = '', buffer = nil, silent = true, noremap = true, nowait = true, } local mappings = { [','] = { 'b#', icons.ui.History .. 'Recent' }, q = { 'q', icons.ui.Close .. 'Quit' }, Q = { 'qa!', icons.ui.Power .. 'Force Quit!' }, w = { 'w', icons.ui.Save .. 'Save' }, x = { 'x', icons.ui.Pencil .. 'Write and Quit' }, S = { 'ASToggle', icons.ui.Save .. 'AutoSave Toggle' }, c = { name = icons.ui.NeoVim .. 'Config', c = { 'CccConvert', 'Convert Color' }, d = { 'RootDir', 'Root Directory' }, e = { 'e $MYVIMRC', 'Edit Config' }, f = { 'lua vim.lsp.buf.format({async = true})', 'Format File' }, F = { 'retab', 'Fix Tabs' }, i = { vim.show_pos, 'Inspect Position' }, l = { ':g/^\\s*$/d', 'Clean Empty Lines' }, n = { 'set relativenumber!', 'Relative Numbers' }, p = { 'CccPick', 'Pick Color' }, r = { 'Telescope reloader', 'Reload Module' }, R = { 'ReloadConfig', 'Reload Configs' }, }, b = { name = icons.ui.Bug .. 'Debug', b = { 'DapToggleBreakpoint', 'Breakpoint' }, c = { 'DapContinue', 'Continue' }, i = { 'DapStepInto', 'Into' }, l = { "lua require'dap'.run_last()", 'Last' }, o = { 'DapStepOver', 'Over' }, O = { 'DapStepOut', 'Out' }, r = { 'DapToggleRepl', 'Repl' }, R = { 'DapRestartFrame', 'Restart Frame' }, t = { 'DapUIToggle', 'Debugger' }, x = { 'DapTerminate', 'Exit' }, }, c = { name = icons.kind.Property .. 'QuickFix', o = {"copen","Open quickfix list"}, c = {"cclose","Close quickfix list"}, f = {"cfirst","Go to first item in quickfix list"}, l = {"clast","Go to last item in quickfix list"}, n = {"cnext","Go to next item in quickfix list"}, p = {"cprev","Go to previous item in quickfix list"}, }, d = { name = icons.ui.Database .. 'Database', b = { 'DBToggle', 'DB Explorer' }, j = { 'lua require("dbee").next()', 'DB Next' }, k = { 'lua require("dbee").prev()', 'DB Prev' }, s = { 'lua require("dbee").store("csv", "buffer", { extra_arg = 0 })', 'To CSV' }, S = { 'lua require("dbee").store("json", "buffer", { extra_arg = 0 })', 'To JSON' }, t = { 'lua require("dbee").store("table", "buffer", { extra_arg = 0 })', 'To Table' }, }, E = { name = icons.documents.OpenFolder .. 'Explorer', e = { 'NvimTreeToggle', 'File Explorer' }, f = { 'NvimTreeFindFileToggle', 'Toggle file explorer on current file' }, r = { 'NvimTreeRefresh', 'Refresh file explorer' }, }, f = { name = icons.ui.Telescope .. 'Find', b = { 'Telescope buffers', 'Buffers' }, a = { 'lua require("telescope").extensions.menufacture.find_files()', 'All Files' }, d = { 'Telescope file_browser', 'Browse Folders' }, e = { 'Oil', 'Dir Editor' }, f = { 'lua require("telescope").extensions.menufacture.git_files()', 'Find files' }, g = { 'lua require("telescope").extensions.menufacture.live_grep()', 'Find Text' }, G = { 'lua require("telescope").extensions.menufacture.grep_string()', 'Find Word' }, h = { 'Telescope help_tags', 'Help' }, H = { 'Telescope man_pages', 'Man Pages' }, k = { 'Telescope commands', 'Commands' }, K = { 'Telescope keymaps', 'Keymaps' }, l = { 'Telescope resume', 'Last Search' }, L = { 'Telescope loclist', 'Location List' }, n = { 'enew', 'New File' }, r = { 'Telescope oldfiles', 'Recent Files' }, p = { 'Telescope', 'Panel' }, s = { 'Telescope live_grep grep_open_files=true', 'Find in Open Files' }, t = { 'lua require("telescope").extensions.flutter.commands()', 'Flutter Tools' }, u = { 'Telescope undo', 'Undo History' }, U = { 'Telescope colorscheme', 'Colorscheme' }, ['"'] = { 'Telescope registers', 'Registers' }, ['.'] = { 'Telescope symbols', 'Emojis' }, [','] = { 'Nerdy', 'Nerd Glyphs' }, }, g = { name = icons.git.Octoface .. 'Git', a = { 'Gitsigns stage_hunk', 'Stage Hunk' }, A = { 'Gitsigns stage_buffer', 'Stage Buffer' }, b = { 'Gitsigns blame_line', 'Blame' }, B = { 'Telescope git_branches', 'Branches' }, c = { 'Telescope git_bcommits', 'File Commits' }, C = { 'Telescope git_commits', 'Commits' }, f = { 'Git', 'Fugitive' }, F = { 'CoAuthor', 'Find Co Author' }, d = { 'Gitsigns preview_hunk', 'Preview Hunk' }, D = { 'Gitsigns diffthis HEAD', 'Diff' }, g = { 'Fterm lazygit', 'Lazygit' }, j = { 'Gitsigns next_hunk', 'Next Hunk' }, k = { 'Gitsigns prev_hunk', 'Prev Hunk' }, l = { 'Git pull', 'Pull' }, p = { 'Git push', 'Push' }, r = { 'Gitsigns reset_hunk', 'Reset Hunk' }, R = { 'Gitsigns reset_buffer', 'Reset Buffer' }, s = { 'Telescope git_status', 'Changed files' }, S = { 'Telescope git_stash', 'Stashed Changes' }, t = { name = 'Git Toggle', b = { 'Gitsigns toggle_current_line_blame', 'Blame' }, d = { 'Gitsigns toggle_deleted', 'Deleted' }, l = { 'Gitsigns toggle_linehl', 'Line HL' }, n = { 'Gitsigns toggle_numhl', 'Number HL' }, s = { 'Gitsigns toggle_signs', 'Signs' }, w = { 'Gitsigns toggle_word_diff', 'Word Diff' }, }, u = { 'Gitsigns undo_stage_hunk', 'Undo Stage Hunk' }, v = { 'Gitsigns select_hunk', 'Select Hunk' }, }, h = { name = icons.ui.Bookmark .. 'Harpoon' }, l = { name = icons.ui.Gear .. 'LSP', a = { 'Lspsaga code_action', 'Code Action' }, d = { 'Lspsaga peek_definition', 'Peek Definition' }, D = { 'Lspsaga goto_definition', 'Goto Definition' }, f = { 'Lspsaga finder', 'Finder' }, F = { 'Telescope lsp_references', 'References' }, h = { 'Lspsaga hover_doc', 'Hover' }, i = { 'Telescope diagnostics', 'Diagnostics' }, I = { 'Lspsaga show_workspace_diagnostics', 'Workspace Diagnostics' }, j = { 'Lspsaga diagnostic_jump_next', 'Next Diagnostic' }, k = { 'Lspsaga diagnostic_jump_prev', 'Prev Diagnostic' }, l = { "lua require('lsp_lines').toggle()", 'Toggle LSP Lines' }, L = { 'LspInfo', 'LSP Info' }, o = { 'Lspsaga outline', 'Outline' }, p = { 'Telescope lsp_incoming_calls', 'Incoming Calls' }, P = { 'Telescope lsp_outgoing_calls', 'Outgoing Calls' }, r = { 'Lspsaga rename', 'Rename' }, R = { 'Lspsaga project_replace', 'Replace' }, s = { 'Telescope lsp_document_symbols', 'Document Symbols' }, S = { 'Telescope lsp_dynamic_workspace_symbols', 'Workspace Symbols' }, t = { 'Lspsaga peek_type_definition', 'Peek Type Definition' }, T = { 'Lspsaga goto_type_definition', 'Goto Type Definition' }, }, m = { name = icons.kind.Field .. 'Modes', c = { 'CccHighlighterToggle', 'Highlight Colors' }, d = { 'Dashboard', 'Dashboard' }, h = { 'Hardtime toggle', 'Hardtime' }, m = { 'MarkdownPreviewToggle', 'Markdown Preview' }, n = { 'Telescope notify', 'Notifications' }, r = { '%SnipRun', 'Run File' }, s = { 'set spell!', 'Spellcheck' }, z = { 'ZenMode', 'ZenMode' }, Z = { 'Twilight', 'Twilight' }, }, n = { name = icons.ui.Note .. 'Notes', d = { 'Tdo', "Today's Todo" }, e = { 'TdoEntry', "Today's Entry" }, f = { 'TdoFiles', 'All Notes' }, g = { 'TdoFind', 'Find Notes' }, h = { 'Tdo -1', "Yesterday's Todo" }, j = { "put =strftime('%a %d %b %r')", 'Insert Human Date' }, J = { "put =strftime('%F')", 'Insert Date' }, k = { "put =strftime('%r')", 'Insert Human Time' }, K = { "put =strftime('%F-%H-%M')", 'Insert Time' }, l = { 'Tdo 1', "Tomorrow's Todo" }, n = { 'TdoNote', 'New Note' }, s = { 'lua require("tdo").run_with("commit " .. vim.fn.expand("%:p")) vim.notify("Committed!")', 'Commit Note', }, t = { 'TdoTodos', 'Incomplete Todos' }, x = { 'TdoToggle', 'Toggle Todo' }, }, p = { name = icons.ui.Package .. 'Packages', c = { 'Lazy check', 'Check' }, d = { 'Lazy debug', 'Debug' }, p = { 'Lazy', 'Plugins' }, P = { 'Lazy profile', 'Profile' }, m = { 'Mason', 'Mason' }, i = { 'Lazy install', 'Install' }, l = { 'Lazy log', 'Log' }, r = { 'Lazy restore', 'Restore' }, s = { 'Lazy sync', 'Sync' }, u = { 'Lazy update', 'Update' }, x = { 'Lazy clean', 'Clean' }, }, r = { name = icons.diagnostics.Hint .. 'Refactor', b = { "lua require('spectre').open_file_search()", 'Replace Buffer' }, e = { "lua require('refactoring').refactor('Extract Block')", 'Extract Block' }, f = { "lua require('refactoring').refactor('Extract Block To File')", 'Extract To File' }, i = { "lua require('refactoring').refactor('Inline Variable')", 'Inline Variable' }, n = { '', 'Swap Next' }, p = { '', 'Swap Previous' }, r = { '', 'Smart Rename' }, d = { '', 'Go To Definition' }, h = { '', 'List Definition Head' }, l = { '', 'List Definition' }, j = { '', 'Next Usage' }, k = { '', 'Previous Usage' }, R = { "lua require('telescope').extensions.refactoring.refactors()", 'Refactor Commands' }, S = { "lua require('spectre').open()", 'Replace' }, s = { [[:%s/\<\>//gI]], 'Replace Word' }, v = { "lua require('refactoring').refactor('Extract Variable')", 'Extract Variable' }, w = { "lua require('spectre').open_visual({select_word=true})", 'Replace Word' }, }, t = { name = icons.ui.Terminal .. 'Terminal', ['`'] = { 'Sterm', 'Horizontal Terminal' }, n = { 'Sterm node', 'Node' }, p = { 'Sterm bpython', 'Python' }, r = { 'Sterm irb', 'Ruby' }, s = { 'Sterm', 'Horizontal Terminal' }, t = { 'Fterm', 'Terminal' }, v = { 'Vterm', 'Vertical Terminal' }, }, T = { name = icons.ui.Test .. 'Test', f = { 'lua require("neotest").run.run(vim.fn.expand("%"))', 'Run Test' }, F = { 'lua require("neotest").run.run()', 'Run Current Test' }, o = { 'Neotest output-panel', 'Test Output' }, O = { 'Neotest summary', 'Test Summary' }, }, s = { name = icons.ui.Windows .. 'Split', [','] = { 'NavigatorPrevious', 'Previous Split' }, ['-'] = { 's', 'Split Below' }, ['\\'] = { 'v', 'Split Right' }, c = { 'tabclose', 'Close Tab' }, d = { 'c', 'Close Window' }, f = { 'tabfirst', 'First Tab' }, h = { 'h', 'Move Left' }, j = { 'j', 'Move Down' }, k = { 'k', 'Move Up' }, l = { 'l', 'Move Right' }, L = { 'tablast', 'Last Tab' }, o = { 'tabnext', 'Next Tab' }, O = { 'tabprevious', 'Previous Tab' }, p = { 'p', 'Previous Window' }, q = { 'bw', 'Close Current Buf' }, s = { 'split', 'Horizontal Split File' }, t = { 'tabnew', 'New Tab' }, v = { 'vsplit', 'Vertical Split File' }, W = { "lua require'utils'.sudo_write()", 'Force Write' }, w = { 'w', 'Write' }, x = { 'x', 'Write and Quit' }, }, y = { name = icons.ui.Clipboard .. 'Yank', f = { '%y+', 'Copy Whole File' }, p = { 'CRpath', 'Copy Relative Path' }, P = { 'CApath', 'Copy Absolute Path' }, g = { 'lua require"gitlinker".get_buf_range_url()', 'Copy Git URL' }, }, } local vopts = { mode = 'v', prefix = '', buffer = nil, silent = true, noremap = true, nowait = true, } local vmappings = { l = { name = icons.ui.Gear .. 'LSP', a = 'Lspsaga range_code_action', }, r = { name = icons.diagnostics.Hint .. 'Refactor', r = { "lua require('telescope').extensions.refactoring.refactors()", 'Refactor Commands' }, e = { "lua require('refactoring').refactor('Extract Function')", 'Extract Function' }, f = { "lua require('refactoring').refactor('Extract Function To File')", 'Extract To File' }, v = { "lua require('refactoring').refactor('Extract Variable')", 'Extract Variable' }, i = { "lua require('refactoring').refactor('Inline Variable')", 'Inline Variable' }, }, s = { "'<,'>SnipRun", icons.ui.Play .. 'Run Code' }, q = { 'q', icons.ui.Close .. 'Quit' }, Q = { 'qa!', icons.ui.Power .. 'Force Quit!' }, x = { 'x', icons.ui.Pencil .. 'Write and Quit' }, y = { name = icons.ui.Clipboard .. 'Yank', g = { 'lua require"gitlinker".get_buf_range_url("v")', 'Copy Git URL' }, }, } local no_leader_opts = { mode = 'n', prefix = '', buffer = nil, silent = true, noremap = true, nowait = true, } local no_leader_mappings = { [''] = { 'bprevious', 'Previous Buffer' }, [''] = { 'bnext', 'Next Buffer' }, [''] = { 'h', 'Move Left' }, [''] = { 'j', 'Move Down' }, [''] = { 'k', 'Move Up' }, [''] = { 'l', 'Move Right' }, [''] = { 'resize +10', 'Increase window height' }, [''] = { 'resize -10', 'Decrease window height' }, [''] = { 'vertical resize -10', 'Decrease window width' }, [''] = { 'vertical resize +10', 'Increase window width' }, [''] = { 'Telescope find_files', 'Find Files' }, [''] = { 'Fterm lazygit', 'Lazygit' }, ['['] = { name = icons.ui.ArrowLeft .. 'Previous', b = { 'bprevious', 'Buffer' }, B = { 'bfirst', 'First Buffer' }, d = { 'Lspsaga diagnostic_jump_prev', 'Diagnostic' }, e = { 'g;', 'Edit' }, g = { 'Gitsigns prev_hunk', 'Git Hunk' }, j = { '', 'Jump' }, }, [']'] = { name = icons.ui.ArrowRight .. 'Next', b = { 'bnext', 'Buffer' }, B = { 'blast', 'Buffer' }, d = { 'Lspsaga diagnostic_jump_next', 'Diagnostic' }, e = { 'g,', 'Edit' }, g = { 'Gitsigns next_hunk', 'Git Hunk' }, j = { '', 'Jump' }, }, K = { 'Lspsaga hover_doc', 'LSP Hover' }, U = { 'redo', 'Redo' }, } if vim.fn.exists('$TMUX') == 1 then local tmux_mappings = { [''] = { 'NavigatorLeft', 'Move Left' }, [''] = { 'NavigatorDown', 'Move Down' }, [''] = { 'NavigatorUp', 'Move Up' }, [''] = { 'NavigatorRight', 'Move Right' }, [''] = { 'NavigatorPrevious', 'Goto Previous' }, } no_leader_mappings = vim.tbl_extend('force', no_leader_mappings, tmux_mappings) end which_key.setup(setup) which_key.register(mappings, opts) which_key.register(vmappings, vopts) which_key.register(no_leader_mappings, no_leader_opts) which_key.register({ mode = { 'o', 'x' }, i = i, a = a })