local is_available = astronvim.is_available local maps = { i = {}, n = {}, v = {}, t = {} } -- Normal -- -- Standard Operations maps.n["w"] = { "w", desc = "Save" } maps.n["q"] = { "q", desc = "Quit" } maps.n["h"] = { "nohlsearch", desc = "No Highlight" } -- TODO: REMOVE IN v3 maps.n["fn"] = { "enew", desc = "New File" } maps.n["gx"] = { function() astronvim.system_open() end, desc = "Open the file under cursor with system app" } maps.n[""] = { "w!", desc = "Force write" } maps.n[""] = { "q!", desc = "Force quit" } maps.n["Q"] = "" maps.n["|"] = { "vsplit", desc = "Vertical Split" } maps.n["\\"] = { "split", desc = "Horizontal Split" } -- Packer maps.n["pc"] = { "PackerCompile", desc = "Packer Compile" } maps.n["pi"] = { "PackerInstall", desc = "Packer Install" } maps.n["ps"] = { "PackerSync", desc = "Packer Sync" } maps.n["pS"] = { "PackerStatus", desc = "Packer Status" } maps.n["pu"] = { "PackerUpdate", desc = "Packer Update" } -- AstroNvim maps.n["pa"] = { "AstroUpdatePackages", desc = "Update Packer and Mason" } maps.n["pA"] = { "AstroUpdate", desc = "AstroNvim Update" } maps.n["pv"] = { "AstroVersion", desc = "AstroNvim Version" } maps.n["pl"] = { "AstroChangelog", desc = "AstroNvim Changelog" } -- Alpha if is_available "alpha-nvim" then maps.n["d"] = { function() require("alpha").start() end, desc = "Alpha Dashboard" } end if vim.g.heirline_bufferline then -- Manage Buffers maps.n["c"] = { function() astronvim.close_buf(0) end, desc = "Close buffer" } maps.n["C"] = { function() astronvim.close_buf(0, true) end, desc = "Force close buffer" } maps.n[""] = { function() astronvim.nav_buf(vim.v.count > 0 and vim.v.count or 1) end, desc = "Next buffer" } maps.n[""] = { function() astronvim.nav_buf(-(vim.v.count > 0 and vim.v.count or 1)) end, desc = "Previous buffer" } maps.n[">b"] = { function() astronvim.move_buf(vim.v.count > 0 and vim.v.count or 1) end, desc = "Move buffer tab right" } maps.n[" 0 and vim.v.count or 1)) end, desc = "Move buffer tab left" } maps.n["bb"] = { function() astronvim.status.heirline.buffer_picker(function(bufnr) vim.api.nvim_win_set_buf(0, bufnr) end) end, desc = "Select buffer from tabline", } maps.n["bd"] = { function() astronvim.status.heirline.buffer_picker(function(bufnr) astronvim.close_buf(bufnr) end) end, desc = "Delete buffer from tabline", } maps.n["b\\"] = { function() astronvim.status.heirline.buffer_picker(function(bufnr) vim.cmd.split() vim.api.nvim_win_set_buf(0, bufnr) end) end, desc = "Horizontal split buffer from tabline", } maps.n["b|"] = { function() astronvim.status.heirline.buffer_picker(function(bufnr) vim.cmd.vsplit() vim.api.nvim_win_set_buf(0, bufnr) end) end, desc = "Vertical split buffer from tabline", } else -- TODO v3: remove this else block -- Bufdelete if is_available "bufdelete.nvim" then maps.n["c"] = { function() require("bufdelete").bufdelete(0, false) end, desc = "Close buffer" } maps.n["C"] = { function() require("bufdelete").bufdelete(0, true) end, desc = "Force close buffer" } else maps.n["c"] = { "bdelete", desc = "Close buffer" } maps.n["C"] = { "bdelete!", desc = "Force close buffer" } end -- Navigate buffers if is_available "bufferline.nvim" then maps.n[""] = { "BufferLineCycleNext", desc = "Next buffer tab" } maps.n[""] = { "BufferLineCyclePrev", desc = "Previous buffer tab" } maps.n[">b"] = { "BufferLineMoveNext", desc = "Move buffer tab right" } maps.n["BufferLineMovePrev", desc = "Move buffer tab left" } else maps.n[""] = { "bnext", desc = "Next buffer" } maps.n[""] = { "bprevious", desc = "Previous buffer" } end end -- Navigate tabs maps.n["]t"] = { function() vim.cmd.tabnext() end, desc = "Next tab" } maps.n["[t"] = { function() vim.cmd.tabprevious() end, desc = "Previous tab" } -- Comment if is_available "Comment.nvim" then maps.n["/"] = { function() require("Comment.api").toggle.linewise.current() end, desc = "Comment line" } maps.v["/"] = { "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", desc = "Toggle comment line", } end -- GitSigns if is_available "gitsigns.nvim" then maps.n["gj"] = { function() require("gitsigns").next_hunk() end, desc = "Next Git hunk" } maps.n["gk"] = { 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["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["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 -- NeoTree if is_available "neo-tree.nvim" then maps.n["e"] = { "Neotree toggle", desc = "Toggle Explorer" } maps.n["o"] = { "Neotree focus", desc = "Focus Explorer" } end -- Session Manager if is_available "neovim-session-manager" then maps.n["Sl"] = { "SessionManager! load_last_session", desc = "Load last session" } maps.n["Ss"] = { "SessionManager! save_current_session", desc = "Save this session" } maps.n["Sd"] = { "SessionManager! delete_session", desc = "Delete session" } maps.n["Sf"] = { "SessionManager! load_session", desc = "Search sessions" } maps.n["S."] = { "SessionManager! load_current_dir_session", desc = "Load current directory session" } end -- Package Manager if is_available "mason.nvim" then maps.n["pI"] = { "Mason", desc = "Mason Installer" } maps.n["pU"] = { "MasonUpdateAll", desc = "Mason Update" } end -- Smart Splits if is_available "smart-splits.nvim" then -- Better window navigation maps.n[""] = { function() require("smart-splits").move_cursor_left() end, desc = "Move to left split" } maps.n[""] = { function() require("smart-splits").move_cursor_down() end, desc = "Move to below split" } maps.n[""] = { function() require("smart-splits").move_cursor_up() end, desc = "Move to above split" } maps.n[""] = { function() require("smart-splits").move_cursor_right() end, desc = "Move to right split" } -- Resize with arrows maps.n[""] = { function() require("smart-splits").resize_up() end, desc = "Resize split up" } maps.n[""] = { function() require("smart-splits").resize_down() end, desc = "Resize split down" } maps.n[""] = { function() require("smart-splits").resize_left() end, desc = "Resize split left" } maps.n[""] = { function() require("smart-splits").resize_right() end, desc = "Resize split right" } else 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" } end -- SymbolsOutline if is_available "aerial.nvim" then maps.n["lS"] = { function() require("aerial").toggle() end, desc = "Symbols outline" } end -- Telescope if is_available "telescope.nvim" then maps.n["fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Search words" } maps.n["fW"] = { function() require("telescope.builtin").live_grep { additional_args = function(args) return vim.list_extend(args, { "--hidden", "--no-ignore" }) end, } end, desc = "Search words in all files", } maps.n["gt"] = { function() require("telescope.builtin").git_status() end, desc = "Git status" } maps.n["gb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } maps.n["gc"] = { function() require("telescope.builtin").git_commits() end, desc = "Git commits" } maps.n["ff"] = { function() require("telescope.builtin").find_files( { hidden = true } ) end, desc = "Search files" } maps.n["fF"] = { function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end, desc = "Search all files", } maps.n["fb"] = { function() require("telescope.builtin").buffers() end, desc = "Search buffers" } maps.n["fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } maps.n["fm"] = { function() require("telescope.builtin").marks() end, desc = "Search marks" } maps.n["fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Search history" } maps.n["fc"] = { function() require("telescope.builtin").grep_string() end, desc = "Search for word under cursor" } maps.n["sb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" } maps.n["sh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" } maps.n["sm"] = { function() require("telescope.builtin").man_pages() end, desc = "Search man" } maps.n["sr"] = { function() require("telescope.builtin").registers() end, desc = "Search registers" } maps.n["sk"] = { function() require("telescope.builtin").keymaps() end, desc = "Search keymaps" } maps.n["sc"] = { function() require("telescope.builtin").commands() end, desc = "Search commands" } if astronvim.is_available "nvim-notify" then maps.n["sn"] = { function() require("telescope").extensions.notify.notify() end, desc = "Search notifications" } end 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", } maps.n["lD"] = { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" } end -- Terminal if is_available "toggleterm.nvim" then local toggle_term_cmd = astronvim.toggle_term_cmd if vim.fn.executable "lazygit" == 1 then maps.n["gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } maps.n["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } end if vim.fn.executable "node" == 1 then maps.n["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } end if vim.fn.executable "gdu" == 1 then maps.n["tu"] = { function() toggle_term_cmd "gdu" end, desc = "ToggleTerm gdu" } end if vim.fn.executable "btm" == 1 then maps.n["tt"] = { function() toggle_term_cmd "btm" end, desc = "ToggleTerm btm" } end if vim.fn.executable "python" == 1 then maps.n["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } end maps.n["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } maps.n["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } maps.n["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } maps.n[""] = { "ToggleTerm", desc = "Toggle terminal" } maps.t[""] = maps.n[""] maps.n[""] = maps.n[""] maps.t[""] = maps.n[""] end if is_available "nvim-dap" then -- modified function keys found with `showkey -a` in the terminal to get key code -- run `nvim -V3log +quit` and search through the "Terminal info" in the `log` file for the correct keyname maps.n[""] = { function() require("dap").continue() end, desc = "Debugger: Start" } maps.n[""] = { function() require("dap").terminate() end, desc = "Debugger: Stop" } -- Shift+F5 maps.n[""] = { function() require("dap").restart_frame() end, desc = "Debugger: Restart" } -- Control+F5 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" } -- Shift+F11 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["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" } if is_available "nvim-dap-ui" then 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 -- Stay in indent mode maps.v["<"] = { ""] = { ">gv", desc = "indent line" } -- Improved Terminal Navigation maps.t[""] = { "h", desc = "Terminal left window navigation" } maps.t[""] = { "j", desc = "Terminal down window navigation" } maps.t[""] = { "k", desc = "Terminal up window navigation" } maps.t[""] = { "l", desc = "Terminal right window navigation" } -- Custom menu for modification of the user experience if is_available "nvim-autopairs" then maps.n["ua"] = { function() astronvim.ui.toggle_autopairs() end, desc = "Toggle autopairs" } end maps.n["ub"] = { function() astronvim.ui.toggle_background() end, desc = "Toggle background" } if is_available "nvim-cmp" then maps.n["uc"] = { function() astronvim.ui.toggle_cmp() end, desc = "Toggle autocompletion" } end if is_available "nvim-colorizer.lua" then maps.n["uC"] = { "ColorizerToggle", desc = "Toggle color highlight" } end maps.n["uS"] = { function() astronvim.ui.toggle_conceal() end, desc = "Toggle conceal" } maps.n["ud"] = { function() astronvim.ui.toggle_diagnostics() end, desc = "Toggle diagnostics" } maps.n["ug"] = { function() astronvim.ui.toggle_signcolumn() end, desc = "Toggle signcolumn" } maps.n["ui"] = { function() astronvim.ui.set_indent() end, desc = "Change indent setting" } maps.n["ul"] = { function() astronvim.ui.toggle_statusline() end, desc = "Toggle statusline" } maps.n["un"] = { function() astronvim.ui.change_number() end, desc = "Change line numbering" } maps.n["us"] = { function() astronvim.ui.toggle_spell() end, desc = "Toggle spellcheck" } maps.n["up"] = { function() astronvim.ui.toggle_paste() end, desc = "Toggle paste mode" } maps.n["ut"] = { function() astronvim.ui.toggle_tabline() end, desc = "Toggle tabline" } maps.n["uu"] = { function() astronvim.ui.toggle_url_match() end, desc = "Toggle URL highlight" } maps.n["uw"] = { function() astronvim.ui.toggle_wrap() end, desc = "Toggle wrap" } maps.n["uy"] = { function() astronvim.ui.toggle_syntax() end, desc = "Toggle syntax highlight" } maps.n["uN"] = { function() astronvim.ui.toggle_ui_notifications() end, desc = "Toggle UI notifications" } astronvim.set_mappings(astronvim.user_plugin_opts("mappings", maps))