local M = {} local f = require("funcs") local icons = require("config.icons") local maps = f.empty_map_table() M.sections = { p = { desc = icons.Package .. " Packages" }, b = { desc = icons.Buffer .. " Buffers" }, bs = { desc = "Sort Buffers" }, d = { desc = icons.Bug .. " Debugger" }, g = { desc = icons.Git .. " Git" }, f = { desc = icons.Search .. " Find" }, l = { desc = icons.Code .. " LSP" }, t = { desc = icons.Console .. " Terminal" }, u = { desc = icons.Gear .. " Utility" }, n = { desc = icons.Note .. " Notes" }, e = { desc = icons.FileTree .. " File Manager" }, } -- Standard -- maps.n["j"] = { "v:count == 0 ? 'gj' : 'j'", expr = true, desc = "Move cursor down" } maps.n["k"] = { "v:count == 0 ? 'gk' : 'k'", expr = true, desc = "Move cursor up" } maps.n["w"] = { "w", desc = "Write buffer" } maps.n["c"] = { "conf q", desc = "Quit" } maps.n["C"] = { "conf qa", desc = "Quit all" } maps.n["n"] = { "ene", desc = "New buffer" } maps.n["h"] = { "noh", desc = "Clear highlight" } maps.n[""] = { "w!", desc = "Force write buffer" } maps.n[""] = { "qa!", desc = "Force quit all" } maps.n["|"] = { "vsplit", desc = "Vertical split" } maps.n["\\"] = { "split", desc = "Horizontal split" } maps.v["<"] = { ""] = { ">gv", desc = "Indent line" } maps.n["q"] = { f.buf_close, desc = "Close buffer" } maps.n[""] = { "" } maps.n[""] = { "" } maps.i[""] = { "" } -- Utility -- if f.is_available("nvim-colorizer.lua") then maps.n["u"] = M.sections.u maps.n["uc"] = { "ColorizerToggle", desc = "Toggle colorizer" } end -- Notes -- if f.is_available("zk-nvim") then maps.n["n"] = M.sections.n maps.v["n"] = maps.n["n"] maps.n["nn"] = { function() require("zk").new({ notebook_path = vim.g.wikidir, title = vim.fn.input("Title: ") }) end, desc = "New Note", } maps.v["nnt"] = { ":ZkNewFromTitleSelection { notebook_path = vim.g.wikidir }", desc = "New Note (Selection as title)", } maps.v["nnc"] = { ":ZkNewFromContentSelection { notebook_path = vim.g.wikidir, title = vim.fn.input('Title: ') }", desc = "New Note (Selection as content)", } maps.n["no"] = { function() require("zk").edit({ notebook_path = vim.g.wikidir }) end, desc = "Open Note", } maps.n["ni"] = { function() require("zk").index({ notebook_path = vim.g.wikidir }) end, desc = "Index Notes", } end -- Window Navigation -- maps.n[""] = { "h", desc = "Move to left split" } maps.n[""] = { "j", desc = "Move to below split" } maps.n[""] = { "k", desc = "Move to above split" } maps.n[""] = { "l", desc = "Move to right split" } maps.n[""] = { "resize -2", desc = "Resize split up" } maps.n[""] = { "resize +2", desc = "Resize split down" } maps.n[""] = { "vertical resize -2", desc = "Resize split left" } maps.n[""] = { "vertical resize +2", desc = "Resize split right" } maps.t[""] = { "wincmd h", desc = "Terminal left window navigation" } maps.t[""] = { "wincmd j", desc = "Terminal down window navigation" } maps.t[""] = { "wincmd k", desc = "Terminal up window navigation" } maps.t[""] = { "wincmd l", desc = "Terminal right window navigation" } -- Plugin Manager -- maps.n["p"] = M.sections.p maps.n["ph"] = { function() require("lazy").home() end, desc = "Home", } maps.n["pi"] = { function() require("lazy").install() end, desc = "Install", } maps.n["pu"] = { function() require("lazy").update() end, desc = "Update", } maps.n["ps"] = { function() require("lazy").sync() end, desc = "Sync", } maps.n["px"] = { function() require("lazy").clean() end, desc = "Clean", } maps.n["pc"] = { function() require("lazy").check() end, desc = "Check", } maps.n["pl"] = { function() require("lazy").log() end, desc = "Log", } maps.n["pr"] = { function() require("lazy").restore() end, desc = "Restore", } maps.n["pp"] = { function() require("lazy").profile() end, desc = "Profile", } maps.n["pd"] = { function() require("lazy").debug() end, desc = "Debug", } maps.n["p?"] = { function() require("lazy").help() end, desc = "Help", } if f.is_available("bufferline.nvim") then maps.n[""] = { function() require("bufferline").cycle(1) end, desc = "Switch to next buffer", } maps.n[""] = { function() require("bufferline").cycle(-1) end, desc = "Switch to previous buffer", } maps.n[""] = { function() require("bufferline").move(1) end, desc = "Move buffer to next", } maps.n[""] = { function() require("bufferline").move(-1) end, desc = "Move buffer to previous", } maps.n["b"] = M.sections.b maps.n["bc"] = { function() require("bufferline").close_others() end, desc = "Close other buffers", } maps.n["bl"] = { function() require("bufferline").close_in_direction("left") end, desc = "Close lefthand buffers", } maps.n["br"] = { function() require("bufferline").close_in_direction("right") end, desc = "Close righthand buffers", } maps.n["bs"] = M.sections.bs maps.n["bse"] = { function() require("bufferline").sort_by("extension") end, desc = "By extension", } maps.n["bsd"] = { function() require("bufferline").sort_by("directory") end, desc = "By directory", } maps.n["bsr"] = { function() require("bufferline").sort_by("relative_directory") end, desc = "By relative directory", } maps.n["bst"] = { function() require("bufferline").sort_by("tabs") end, desc = "By tabs", } end if f.is_available("Comment.nvim") then maps.n["/"] = { function() require("Comment.api").toggle.linewise.count(vim.v.count > 0 and vim.v.count or 1) end, desc = "Toggle comment line", } maps.v["/"] = { "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", desc = "Toggle comment for selection", } end if f.is_available("gitsigns.nvim") then maps.n["g"] = M.sections.g maps.n["]g"] = { function() require("gitsigns").next_hunk() end, desc = "Next Git hunk", } maps.n["[g"] = { function() require("gitsigns").prev_hunk() end, desc = "Previous Git hunk", } maps.n["gl"] = { function() require("gitsigns").blame_line() end, desc = "View Git blame", } maps.n["gL"] = { function() require("gitsigns").blame_line({ full = true }) end, desc = "View full Git blame", } maps.n["gp"] = { function() require("gitsigns").preview_hunk() end, desc = "Preview Git hunk", } maps.n["gh"] = { function() require("gitsigns").reset_hunk() end, desc = "Reset Git hunk", } maps.n["gr"] = { function() require("gitsigns").reset_buffer() end, desc = "Reset Git buffer", } maps.n["gs"] = { function() require("gitsigns").stage_hunk() end, desc = "Stage Git hunk", } maps.n["gS"] = { function() require("gitsigns").stage_buffer() end, desc = "Stage Git buffer", } maps.n["gu"] = { function() require("gitsigns").undo_stage_hunk() end, desc = "Unstage Git hunk", } maps.n["gd"] = { function() require("gitsigns").diffthis() end, desc = "View Git diff", } end if f.is_available("taolf") then maps.n["e"] = M.sections.e maps.n["E"] = { function() require("taolf").start({ dir = "fd" }) end, desc = "File manager", } maps.n["gE"] = { "" } maps.n["ee"] = { function() require("taolf").start() end, desc = "File manager", } maps.n["eg"] = { function() require("taolf").start({ dir = "gwd" }) end, desc = "File manager in git working directory", } maps.n["ef"] = { function() require("taolf").start({ dir = "fd" }) end, desc = "File manager in open file's working directory", } end if f.is_available("mason.nvim") then maps.n["pm"] = { "Mason", desc = "Mason" } end if f.is_available("aerial.nvim") then maps.n["l"] = M.sections.l maps.n["lS"] = { function() require("aerial").toggle() end, desc = "Symbols outline", } end if f.is_available("telescope.nvim") then maps.n["f"] = M.sections.f maps.n["g"] = M.sections.g maps.n["gb"] = { function() require("telescope.builtin").git_branches({ use_file_path = true }) end, desc = "Git branches", } maps.n["gc"] = { function() require("telescope.builtin").git_commits({ use_file_path = true }) end, desc = "Git commits (repository)", } maps.n["gC"] = { function() require("telescope.builtin").git_bcommits({ use_file_path = true }) end, desc = "Git commits (current file)", } maps.n["gt"] = { function() require("telescope.builtin").git_status({ use_file_path = true }) end, desc = "Git status", } maps.n["f"] = { function() require("telescope.builtin").resume() end, desc = "Resume previous search", } maps.n["f'"] = { function() require("telescope.builtin").marks() end, desc = "Find marks", } maps.n["f/"] = { function() require("telescope.builtin").current_buffer_fuzzy_find() end, desc = "Find words in current buffer", } maps.n["fc"] = { function() require("telescope.builtin").grep_string() end, desc = "Find word under cursor", } maps.n["fC"] = { function() require("telescope.builtin").commands() end, desc = "Find commands", } maps.n["ff"] = { function() require("telescope.builtin").find_files() end, desc = "Find files", } maps.n["fF"] = { function() require("telescope.builtin").find_files({ hidden = true, no_ignore = true }) end, desc = "Find all files", } maps.n["fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Find help", } maps.n["fk"] = { function() require("telescope.builtin").keymaps() end, desc = "Find keymaps", } maps.n["fm"] = { function() require("telescope.builtin").man_pages() end, desc = "Find man", } maps.n["fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Find history", } maps.n["fr"] = { function() require("telescope.builtin").registers() end, desc = "Find registers", } maps.n["fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Find words", } -- maps.n["fb"] = { function() require("telescope.builtin").buffers() end, desc = "Find buffers" } maps.n["ft"] = { function() require("telescope").extensions["todo-comments"].todo() end, desc = "Find buffers", } maps.n["fW"] = { function() require("telescope.builtin").live_grep({ additional_args = function(args) return vim.list_extend(args, { "--hidden", "--no-ignore" }) end, }) end, desc = "Find words in all files", } maps.n["l"] = M.sections.l maps.n["ls"] = { function() local aerial_avail, _ = pcall(require, "aerial") if aerial_avail then require("telescope").extensions.aerial.aerial() else require("telescope.builtin").lsp_document_symbols() end end, desc = "Search symbols", } end if f.is_available("toggleterm.nvim") then maps.n["t"] = M.sections.t if vim.fn.executable("lazygit") == 1 then maps.n["g"] = M.sections.g maps.n["gg"] = { function() local worktree = f.file_worktree() local flags = worktree and (" --work-tree=%s --git-dir=%s"):format(worktree.toplevel, worktree.gitdir) or "" f.toggle_term_cmd("lazygit " .. flags) end, desc = "ToggleTerm lazygit", } maps.n["tl"] = maps.n["gg"] end if vim.fn.executable("node") == 1 then maps.n["tn"] = { function() f.toggle_term_cmd("node") end, desc = "ToggleTerm node", } end if vim.fn.executable("gdu") == 1 then maps.n["tu"] = { function() f.toggle_term_cmd("gdu") end, desc = "ToggleTerm gdu", } end if vim.fn.executable("btm") == 1 then maps.n["tt"] = { function() f.toggle_term_cmd("btm") end, desc = "ToggleTerm btm", } end local python = vim.fn.executable("python") == 1 and "python" or vim.fn.executable("python3") == 1 and "python3" if python then maps.n["tp"] = { function() f.toggle_term_cmd(python) end, desc = "ToggleTerm python", } end maps.n["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } maps.n["th"] = { "ToggleTerm direction=horizontal", desc = "ToggleTerm horizontal split" } maps.n[""] = { "ToggleTerm", desc = "Toggle terminal" } maps.t[""] = maps.n[""] end if f.is_available("nvim-dap") then local conditional_breakpoint = function() vim.ui.input({ prompt = "Condition: " }, function(condition) if condition then require("dap").set_breakpoint(condition) end end) end maps.n["d"] = M.sections.d maps.v["d"] = M.sections.d maps.n[""] = { function() require("dap").continue() end, desc = "Debugger: Start", } maps.n[""] = { function() require("dap").terminate() end, desc = "Debugger: Stop", } maps.n[""] = { conditional_breakpoint, desc = "Debugger: Conditional Breakpoint" } maps.n[""] = { function() require("dap").restart_frame() end, desc = "Debugger: Restart", } maps.n[""] = { function() require("dap").pause() end, desc = "Debugger: Pause", } maps.n[""] = { function() require("dap").toggle_breakpoint() end, desc = "Debugger: Toggle Breakpoint", } maps.n[""] = { function() require("dap").step_over() end, desc = "Debugger: Step Over", } maps.n[""] = { function() require("dap").step_into() end, desc = "Debugger: Step Into", } maps.n[""] = { function() require("dap").step_out() end, desc = "Debugger: Step Out", } maps.n["db"] = { function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint (F9)", } maps.n["dB"] = { function() require("dap").clear_breakpoints() end, desc = "Clear Breakpoints", } maps.n["dc"] = { function() require("dap").continue() end, desc = "Start/Continue (F5)", } maps.n["dC"] = { conditional_breakpoint, desc = "Conditional Breakpoint (S-F9)" } maps.n["di"] = { function() require("dap").step_into() end, desc = "Step Into (F11)", } maps.n["do"] = { function() require("dap").step_over() end, desc = "Step Over (F10)", } maps.n["dO"] = { function() require("dap").step_out() end, desc = "Step Out (S-F11)", } maps.n["dq"] = { function() require("dap").close() end, desc = "Close Session", } maps.n["dQ"] = { function() require("dap").terminate() end, desc = "Terminate Session (S-F5)", } maps.n["dp"] = { function() require("dap").pause() end, desc = "Pause (F6)", } maps.n["dr"] = { function() require("dap").restart_frame() end, desc = "Restart (C-F5)", } maps.n["dR"] = { function() require("dap").repl.toggle() end, desc = "Toggle REPL", } maps.n["ds"] = { function() require("dap").run_to_cursor() end, desc = "Run To Cursor", } if f.is_available("nvim-dap-ui") then maps.n["dE"] = { function() vim.ui.input({ prompt = "Expression: " }, function(expr) if expr then require("dapui").eval(expr, { enter = true }) end end) end, desc = "Evaluate Input", } maps.v["dE"] = { function() require("dapui").eval() end, desc = "Evaluate Input", } maps.n["du"] = { function() require("dapui").toggle() end, desc = "Toggle Debugger UI", } maps.n["dh"] = { function() require("dap.ui.widgets").hover() end, desc = "Debugger Hover", } end end if f.is_available("nvim-ufo") then maps.n["zR"] = { function() require("ufo").openAllFolds() end, desc = "Open all folds", } maps.n["zM"] = { function() require("ufo").closeAllFolds() end, desc = "Close all folds", } maps.n["zr"] = { function() require("ufo").openFoldsExceptKinds() end, desc = "Fold less", } maps.n["zm"] = { function() require("ufo").closeFoldsWith() end, desc = "Fold more", } maps.n["zp"] = { function() require("ufo").peekFoldedLinesUnderCursor() end, desc = "Peek fold", } end M.maps = maps return M