local which_key = require('which-key') local icons = require('lib.icons') local setup = { preset = 'modern', 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, }, }, icons = { breadcrumb = icons.ui.ArrowOpen, separator = icons.ui.Arrow, group = '', keys = { Space = icons.ui.Rocket, }, rules = false, -- enable auto icon rules }, win = { no_overlap = true, border = 'rounded', width = 0.8, height = { min = 5, max = 25 }, padding = { 1, 2 }, title = true, title_pos = 'center', zindex = 1000, wo = { winblend = 10, }, }, layout = { width = { min = 20 }, spacing = 6, align = 'center', }, show_help = false, show_keys = true, triggers = true, } 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 = { 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.ui.Neovim .. 'Code', c = { 'CccHighlighterToggle', 'Highlight Colors' }, d = { 'RootDir', 'Root Directory' }, f = { 'lua vim.lsp.buf.format({async = true})', 'Format File' }, F = { 'retab', 'Fix Tabs' }, h = { 'Hardtime toggle', 'Hardtime' }, l = { ':g/^\\s*$/d', 'Clean Empty Lines' }, m = { 'MarkdownPreviewToggle', 'Markdown Preview' }, n = { 'Telescope notify', 'Notifications' }, o = { 'Dashboard', 'Dashboard' }, p = { 'CccPick', 'Pick Color' }, P = { 'CccConvert', 'Convert Color' }, r = { 'Telescope reloader', 'Reload Module' }, R = { 'ReloadConfig', 'Reload Configs' }, x = { '%SnipRun', 'Run File' }, }, 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.ui.Pencil .. 'Edit', a = { 'b#', 'Alternate File' }, c = { 'e $MYVIMRC', 'Config' }, d = { 'lua require("telescope.builtin").find_files({cwd = vim.fn.stdpath("config")})', 'Config Dir' }, e = { 'NvimTreeToggle', 'Explorer' }, f = { 'gf', 'File Under Cursor' }, l = { 'e ~/.config/shell/local.sh', 'Local Config' }, m = { 'e README.md', 'Readme' }, n = { 'enew', 'New File' }, z = { 'e $ZDOTDIR/.zshrc', 'Zsh Config' }, }, f = { name = icons.ui.Telescope .. 'Find', a = { 'lua require("telescope").extensions.menufacture.find_files()', 'All Files' }, b = { 'Telescope buffers', 'Buffers' }, c = { 'Telescope git_bcommits', 'File Commits' }, f = { 'lua require("telescope").extensions.menufacture.git_files()', 'Find files' }, g = { 'lua require("telescope").extensions.menufacture.live_grep()', 'Find Text' }, l = { 'Telescope loclist', 'Location List' }, m = { 'Telescope git_status', 'Modified files' }, o = { 'Telescope live_grep grep_open_files=true', 'Find in Open Files' }, p = { 'Telescope resume', 'Last Search' }, q = { 'Telescope quickfix', 'Quickfix' }, r = { 'Telescope oldfiles', 'Recent Files' }, s = { 'Telescope current_buffer_fuzzy_find', 'Fuzzy Find in File' }, t = { 'Telescope', 'Panel' }, u = { 'Telescope undo', 'Undo History' }, w = { 'lua require("telescope").extensions.menufacture.grep_string()', 'Find Word' }, }, g = { name = icons.git.Octoface .. 'Git', a = { 'Gitsigns stage_hunk', 'Stage Hunk' }, A = { 'Gitsigns stage_buffer', 'Stage Buffer' }, b = { "lua require('gitsigns').blame_line({full = true})", 'Blame' }, c = { 'Telescope git_commits', 'Find Commits' }, C = { 'CoAuthor', 'Co-Authors' }, d = { 'Gitsigns diffthis HEAD', 'Diff' }, f = { 'Git', 'Fugitive Panel' }, g = { 'Fterm lazygit', 'Lazygit' }, i = { 'Gitsigns preview_hunk', 'Hunk Info' }, j = { 'Gitsigns next_hunk', 'Next Hunk' }, k = { 'Gitsigns prev_hunk', 'Prev Hunk' }, l = { 'Git log', 'Log' }, p = { 'Git pull', 'Pull' }, P = { 'Git push', 'Push' }, r = { 'Gitsigns reset_hunk', 'Reset Hunk' }, R = { 'Gitsigns reset_buffer', 'Reset Buffer' }, s = { 'Telescope git_branches', 'Switch Branch' }, S = { 'Telescope git_stash', 'Stashed Changes' }, t = { name = '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.Question .. 'Help', h = { 'Telescope help_tags', 'Help Pages' }, i = { vim.show_pos, 'Inspect Position' }, k = { 'Lspsaga hover_doc', 'Hover Doc' }, m = { 'Telescope man_pages', 'Man Pages' }, }, i = { name = icons.ui.Download .. 'Insert', d = { "put =strftime('## %a %d %b %r')", 'Date' }, e = { 'Telescope symbols', 'Emojis' }, f = { "put =expand('%:t')", 'File Name' }, n = { 'Nerdy', 'Nerd Glyphs' }, P = { 'put %:p', 'Absolute Path' }, p = { 'put %', 'Relative Path' }, r = { 'Telescope registers', 'Registers' }, t = { "put =strftime('## %r')", 'Time' }, }, j = { name = icons.ui.Jump .. 'Jump', c = { '*', 'Word' }, d = { 'FlashDiagnostics', 'Diagnostics' }, f = { 'Telescope jumplist', 'Jumplist' }, h = { '', 'Backward' }, j = { "lua require('flash').remote()", 'Remote' }, k = { "lua require('flash').treesitter()", 'Treesitter' }, l = { '', 'Forward' }, n = { "lua require('flash').jump({search = { forward = true, wrap = false, multi_window = false },})", 'Search Forward', }, N = { "lua require('flash').jump({search = { forward = false, wrap = false, multi_window = false },})", 'Search Backward', }, p = { "lua require('flash').jump({continue = true})", 'Previous Jump' }, s = { "lua require('flash').jump()", 'Search' }, t = { "lua require('flash').treesitter_search()", 'Remote Treesitter' }, w = { 'lua require("flash").jump({ pattern = vim.fn.expand("")})', 'Current Word' }, }, k = { name = icons.ui.Keyboard .. 'Keys', c = { 'Telescope commands', 'Commands' }, h = { 'Telescope command_history', 'Command History' }, k = { 'Telescope keymaps', 'Keymaps' }, s = { 'Telescope search_history', 'Search History' }, }, l = { name = icons.kind.TypeParameter .. 'LSP', a = { 'Lspsaga code_action', 'Code Action' }, d = { 'Lspsaga peek_definition', 'Peek Definition' }, f = { 'Lspsaga finder', 'Finder' }, F = { 'Telescope lsp_references layout_strategy=vertical', 'References' }, g = { 'Lspsaga goto_definition', 'Goto Definition' }, h = { 'Lspsaga hover_doc', 'Hover' }, i = { 'LspInfo', 'LSP Info' }, j = { 'Lspsaga diagnostic_jump_next', 'Next Diagnostic' }, k = { 'Lspsaga diagnostic_jump_prev', 'Prev Diagnostic' }, L = { 'Lspsaga show_workspace_diagnostics', 'Workspace Diagnostics' }, l = { 'Telescope diagnostics layout_strategy=vertical', 'File Diagnostics' }, o = { 'Lspsaga outline', 'Outline' }, p = { 'Telescope lsp_incoming_calls', 'Incoming Calls' }, P = { 'Telescope lsp_outgoing_calls', 'Outgoing Calls' }, q = { 'LspStop', 'Stop LSP' }, Q = { 'LspRestart', 'Restart LSP' }, R = { 'Lspsaga project_replace', 'Replace' }, r = { 'Lspsaga rename', 'Rename' }, s = { 'Telescope lsp_document_symbols theme=get_ivy', 'Document Symbols' }, S = { 'Telescope lsp_dynamic_workspace_symbols', 'Workspace Symbols' }, T = { 'Lspsaga goto_type_definition', 'Goto Type Definition' }, t = { 'Lspsaga peek_type_definition', 'Peek Type Definition' }, }, m = { name = icons.ui.Bookmark .. 'Marks', b = { "lua require('telescope').extensions.marks_nvim.bookmarks_list_all()", 'Bookmarks' }, d = { "lua require('marks').delete_line()", 'Delete Line' }, D = { "lua require('marks').delete_buf()", 'Delete Buffer' }, h = { "lua require('marks').next_bookmark()", 'Next Bookmark' }, j = { "lua require('marks').next()", 'Next' }, k = { "lua require('marks').prev()", 'Previous' }, l = { "lua require('marks').prev_bookmark()", 'Previous Bookmark' }, m = { 'Telescope marks', 'All Marks' }, P = { "lua require('marks').preview()", 'Preview' }, s = { "lua require('marks').set_next()", 'Set Next' }, t = { "lua require('marks').toggle()", 'Toggle' }, x = { "lua require('marks').delete_bookmark()", 'Delete Bookmark' }, ['1'] = { "lua require('marks').toggle_bookmark1()", 'Toggle Bookmark 0' }, ['2'] = { "lua require('marks').toggle_bookmark2()", 'Toggle Bookmark 2' }, ['3'] = { "lua require('marks').toggle_bookmark3()", 'Toggle Bookmark 3' }, ['4'] = { "lua require('marks').toggle_bookmark4()", 'Toggle Bookmark 4' }, n = { name = 'Next Bookmark Group', ['1'] = { "lua require('marks').next_bookmark1()", 'Next Bookmark 1' }, ['2'] = { "lua require('marks').next_bookmark2()", 'Next Bookmark 2' }, ['3'] = { "lua require('marks').next_bookmark3()", 'Next Bookmark 3' }, ['4'] = { "lua require('marks').next_bookmark4()", 'Next Bookmark 4' }, }, p = { name = 'Previous Bookmark Group', ['1'] = { "lua require('marks').prev_bookmark1()", 'Previous Bookmark 1' }, ['2'] = { "lua require('marks').prev_bookmark2()", 'Previous Bookmark 2' }, ['3'] = { "lua require('marks').prev_bookmark3()", 'Previous Bookmark 3' }, ['4'] = { "lua require('marks').prev_bookmark4()", 'Previous Bookmark 4' }, }, }, 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" }, 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' }, }, o = { name = icons.ui.Gear .. 'Options', c = { 'Telescope colorscheme', 'Colorscheme' }, h = { 'Telescope highlights', 'Highlight Colors' }, n = { 'set relativenumber!', 'Relative Numbers' }, o = { 'Telescope vim_options', 'All Options' }, }, p = { name = icons.ui.Package .. 'Packages', c = { 'Lazy check', 'Check' }, d = { 'Lazy debug', 'Debug' }, i = { 'Lazy install', 'Install' }, l = { 'Lazy log', 'Log' }, m = { 'Mason', 'Mason' }, P = { 'Lazy profile', 'Profile' }, p = { 'Lazy', 'Plugins' }, r = { 'Lazy restore', 'Restore' }, s = { 'Lazy sync', 'Sync' }, u = { 'Lazy update', 'Update' }, x = { 'Lazy clean', 'Clean' }, }, q = { name = icons.ui.Close .. 'Quit', a = { 'qall', 'Quit All' }, b = { 'bw', 'Close Buffer' }, d = { 'bdelete', 'Delete Buffer' }, f = { 'qall!', 'Force Quit' }, q = { 'q', 'Quit' }, s = { 'c', 'Close Split' }, w = { 'wq', 'Write and Quit' }, }, r = { name = icons.ui.Code .. 'Refactor', b = { "lua require('spectre').open_file_search()", 'Replace Buffer' }, d = { '', 'Go To Definition' }, e = { "lua require('refactoring').refactor('Extract Block')", 'Extract Block' }, f = { "lua require('refactoring').refactor('Extract Block To File')", 'Extract To File' }, h = { '', 'List Definition Head' }, i = { "lua require('refactoring').refactor('Inline Variable')", 'Inline Variable' }, j = { '', 'Next Usage' }, k = { '', 'Previous Usage' }, l = { '', 'List Definition' }, n = { '', 'Swap Next' }, p = { '', 'Swap Previous' }, R = { "lua require('telescope').extensions.refactoring.refactors()", 'Refactor Commands' }, r = { '', 'Smart Rename' }, 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' }, }, s = { name = icons.ui.Windows .. 'Split', ['`'] = { 'p', 'Previous Window' }, ['\\'] = { 'v', 'Split Right' }, ['/'] = { 's', 'Split Below' }, ['-'] = { 'vertical resize -20', 'Decrease window width' }, ['='] = { 'vertical resize +20', 'Increase window width' }, ['_'] = { 'resize -10', 'Decrease window height' }, ['+'] = { 'resize +10', 'Increase window height' }, a = { 'split', 'Horizontal Split' }, c = { 'tabclose', 'Close Tab' }, f = { 'tabfirst', 'First Tab' }, h = { 'h', 'Move Left' }, H = { 'vertical resize -10', 'Decrease window width' }, j = { 'j', 'Move Down' }, J = { 'resize -5', 'Decrease window height' }, k = { 'k', 'Move Up' }, K = { 'resize +5', 'Increase window height' }, l = { 'l', 'Move Right' }, L = { 'vertical resize +10', 'Increase window width' }, p = { 'NavigatorPrevious', 'Previous Pane' }, q = { 'c', 'Close Split' }, s = { 'vsplit', 'Vertical Split' }, }, t = { name = icons.ui.Terminal .. 'Terminal', ['`'] = { 'Sterm', 'Horizontal Terminal' }, c = { 'Sterm bundle exec rails console', 'Rails Console' }, d = { 'Sterm dexe', 'Exe Launcher' }, n = { 'Sterm node', 'Node' }, p = { 'Sterm bpython', 'Python' }, r = { 'Sterm irb', 'Ruby' }, s = { 'Sterm', 'Horizontal Terminal' }, t = { 'Fterm', 'Terminal' }, v = { 'Vterm', 'Vertical Terminal' }, w = { 'Sterm dexe --wait-before-exit', 'Exe Launcher, Wait' }, }, u = { name = icons.ui.Test .. 'Test', c = { 'lua require("neotest").run.run()', 'Run Current Test' }, f = { 'lua require("neotest").run.run(vim.fn.expand("%"))', 'Run Test File' }, o = { 'Neotest output-panel', 'Test Output' }, s = { 'Neotest summary', 'Test Summary' }, }, v = { name = icons.ui.Star .. 'Select', B = { 'vab', 'Around Bracket' }, b = { 'vib', 'Bracket' }, P = { 'vap', 'Around Para' }, p = { 'vip', 'Paragraph' }, Q = { 'vaq', 'Around Quote' }, q = { 'viq', 'Quote' }, }, w = { name = icons.kind.File .. 'Writing', c = { 'set spell!', 'Spellcheck' }, f = { "lua require'utils'.sudo_write()", 'Force Write' }, j = { ']s', 'Next Misspell' }, k = { '[s', 'Prev Misspell' }, q = { 'wq', 'Write and Quit' }, s = { 'Telescope spell_suggest', 'Suggestions' }, t = { 'Twilight', 'Twilight' }, w = { 'w', 'Write and Quit' }, z = { 'ZenMode', 'ZenMode' }, }, x = { 'x', icons.ui.SignOut .. 'Save and Quit' }, y = { name = icons.ui.Clipboard .. 'Yank', a = { '%y+', 'Copy Whole File' }, f = { 'CopyFileName', 'File Name' }, g = { 'lua require"gitlinker".get_buf_range_url()', 'Copy Git URL' }, P = { 'CopyAbsolutePath', 'Absolute Path' }, p = { 'CopyRelativePath', 'Relative Path' }, }, } local vopts = { mode = 'v', prefix = '', buffer = nil, silent = true, noremap = true, nowait = true, } local vmappings = { c = { name = icons.ui.Neovim .. 'Code', i = { ':sort i', 'Sort Case Insensitive' }, S = { ':sort!', 'Sort Desc' }, s = { ':sort', 'Sort Asc' }, u = { ':!uniq', 'Unique' }, x = { "'<,'>SnipRun", 'Run Code' }, }, g = { name = icons.git.Octoface .. 'Git', a = { 'Gitsigns stage_hunk', 'Stage Hunk' }, r = { 'Gitsigns reset_hunk', 'Reset Hunk' }, }, j = { name = icons.ui.Jump .. 'Jump', d = { 'FlashDiagnostics', 'Diagnostics' }, j = { "lua require('flash').remote()", 'Remote' }, k = { "lua require('flash').treesitter()", 'Treesitter' }, n = { "lua require('flash').jump({search = { forward = true, wrap = false, multi_window = false },})", 'Search Forward', }, N = { "lua require('flash').jump({search = { forward = false, wrap = false, multi_window = false },})", 'Search Backward', }, p = { "lua require('flash').jump({continue = true})", 'Previous Jump' }, s = { "lua require('flash').jump()", 'Search' }, t = { "lua require('flash').treesitter_search()", 'Remote Treesitter' }, w = { 'lua require("flash").jump({ pattern = vim.fn.expand("")})', 'Current Word' }, }, l = { name = icons.kind.TypeParameter .. 'LSP', a = 'Lspsaga range_code_action', }, r = { name = icons.ui.Code .. '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' }, }, 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 = { K = { 'Lspsaga hover_doc', 'LSP Hover' }, Q = { 'qall!', 'Force Quit!' }, U = { 'redo', 'Redo' }, [''] = { 'bprevious', 'Previous Buffer' }, [''] = { 'bnext', 'Next Buffer' }, [''] = { 'Telescope find_files', 'Find Files' }, [''] = { 'Fterm lazygit', 'Lazygit' }, [''] = { 'h', 'Move Left' }, [''] = { 'j', 'Move Down' }, [''] = { 'k', 'Move Up' }, [''] = { 'l', 'Move Right' }, [''] = { 'p', 'Previous Pane' }, [''] = { 'resize +10', 'Increase window height' }, [''] = { 'resize -10', 'Decrease window height' }, [''] = { 'vertical resize -10', 'Decrease window width' }, [''] = { 'vertical resize +10', 'Increase window width' }, ['['] = { 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' }, }, } if vim.fn.exists('$TMUX') == 1 then local tmux_mappings = { [''] = { 'NavigatorLeft', 'Move Left' }, [''] = { 'NavigatorDown', 'Move Down' }, [''] = { 'NavigatorUp', 'Move Up' }, [''] = { 'NavigatorRight', 'Move Right' }, [''] = { 'NavigatorPrevious', 'Previous Pane' }, } 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 })