local is_available = astronvim.is_available local maps = { n = {}, v = {}, t = {}, [""] = {} } maps[""][""] = "" -- Normal -- -- Standard Operations maps.n["w"] = { "w", desc = "Save" } maps.n["q"] = { "q", desc = "Quit" } maps.n["h"] = { "nohlsearch", desc = "No Highlight" } maps.n["u"] = { function() astronvim.toggle_url_match() end, desc = "Toggle URL Highlights" } maps.n["fn"] = { "enew", desc = "New File" } maps.n["gx"] = { function() astronvim.url_opener() 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"] = "" -- 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" } -- Alpha if is_available "alpha-nvim" then maps.n["d"] = { "Alpha", desc = "Alpha Dashboard" } end -- Bufdelete if is_available "bufdelete.nvim" then maps.n["c"] = { "Bdelete", desc = "Close window" } else maps.n["c"] = { "bdelete", desc = "Close window" } 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 -- Comment if is_available "Comment.nvim" then maps.n["/"] = { function() require("Comment.api").toggle_current_linewise() end, desc = "Comment line" } maps.v["/"] = { "lua require('Comment.api').toggle_linewise_op(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 -- LSP Installer if is_available "nvim-lsp-installer" then maps.n["li"] = { "LspInfo", desc = "LSP information" } maps.n["lI"] = { "LspInstallInfo", desc = "LSP installer" } 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"] = { "AerialToggle", 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() 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["sn"] = { function() require("telescope").extensions.notify.notify() end, desc = "Search notifications" } 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" } 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["lR"] = { function() require("telescope.builtin").lsp_references() end, desc = "Search references" } 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 maps.n[""] = { "ToggleTerm", desc = "Toggle terminal" } maps.n["gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } maps.n["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } maps.n["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } maps.n["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } maps.n["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } maps.n["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } 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" } end -- Stay in indent mode maps.v["<"] = { ""] = { ">gv", desc = "indent line" } -- Improved Terminal Mappings maps.t[""] = { "", desc = "Terminal normal mode" } maps.t["jk"] = { "", desc = "Terminal normal mode" } 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 naviation" } astronvim.set_mappings(astronvim.user_plugin_opts("mappings", maps))