local map = vim.keymap.set local term = require("utils.terminal") local map_from_table = require("utils.keymaps.converters.from_table").set_keybindings local add_to_whichkey = require("utils.keymaps.converters.whichkey").addToWhichKey local telescope_paste_img = require("utils.telescope_extra").find_and_paste_image local term_factory = term.term_factory local term_toggle = term.term_toggle local opts = { silent = true, noremap = true } local nosilent = { silent = false, noremap = true } -- Leader key vim.g.mapleader = " " vim.g.maplocalleader = "," -- Create a custom command with the given trigger, command, and description --- @param trigger string The command trigger --- @param command string The command to execute --- @param description string Description of the command --- @return nil function create_custom_command(trigger, command, description) vim.api.nvim_create_user_command(trigger, command, { desc = description }) end -- Custom commands create_custom_command("Config", "edit ~/.config/nvim", "Edit nvim configuration") create_custom_command("Keymaps", "edit ~/.config/nvim/lua/core/keymaps.lua", "Edit Hyprland keybindings") create_custom_command("Hypr", "edit ~/.config/hypr/hyprland.conf", "Edit Hyprland configuration") vim.keymap.set("", "tl", function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) end, { desc = "Toggle diagnostics virtual text" }) -- {{{ Basic Mappings local basic_mappings = { { key = "", cmd = "zz", desc = "Scroll up and center", mode = "n" }, { key = "n", cmd = "nzzzv", desc = "Next search result and center", mode = "n" }, { key = "N", cmd = "Nzzzv", desc = "Previous search result and center", mode = "n" }, { key = "pp", cmd = '"_dP', desc = "Paste without yanking", mode = "x" }, { key = "<", cmd = "")) end, group = "Generate Stub File", }, } -- }}} -- {{{ Code Companion Mappings local code_companion_mappings = { { mode = "n", key = "cp", cmd = ":vert Copilot panel", group = "Copilot Panel" }, { mode = "n", key = "oc", cmd = ":CodeCompanionChat Toggle", group = "Toggle Codecompanion" }, { mode = "n", key = "Cc", cmd = ":CodeCompanionChat Toggle", group = "Toggle Codecompanion" }, { mode = "n", key = "Ci", cmd = ":CodeCompanion #{buffer} ", group = "Inline CodeCompanion", opts = nosilent, }, { mode = "n", key = "CT", cmd = ":CodeCompanionChat Toggle", group = "CodeCompanion Toggle" }, { mode = "n", key = "Ca", cmd = ":CodeCompanionActions", group = "CodeCompanion Actions" }, { mode = "v", key = "Cc", cmd = ":CodeCompanionChat Add", group = "CodeCompanion Add" }, { mode = "v", key = "Ci", cmd = ":CodeCompanion #{buffer} ", group = "CodeCompanion Inline", opts = nosilent, }, { mode = "v", key = "Ce", cmd = ":CodeCompanion /explain", group = "CodeCompanion /explain" }, { mode = "v", key = "Cf", cmd = ":CodeCompanion /fix", group = "CodeCompanion /fix" }, { mode = "v", key = "Cl", cmd = ":CodeCompanion /lsp", group = "CodeCompanion /lsp" }, { mode = "v", key = "Ct", cmd = ":CodeCompanion /tests", group = "CodeCompanion /tests" }, } -- }}} -- {{{ Telescope mappings local telescope_mappings = { { mode = "n", key = "//", cmd = ":Telescope current_buffer_fuzzy_find previewer=false", "Current buffer fuzzy find", }, { mode = "n", key = "??", cmd = ":Telescope lsp_document_symbols theme=dropdown layout_config={width=0.5}", group = "Lsp document symbols", }, { mode = "n", key = "fc", cmd = ':Telescope color_names theme=dropdown layout_config={width=0.45,height=25,prompt_position="bottom"} layout_strategy=vertical', group = "Telescope color names", }, { mode = "n", key = "Tc", cmd = ":Telescope colorscheme", group = "Telescope colorscheme", }, { mode = "n", key = "TC", cmd = ':Telescope color_names theme=dropdown layout_config={width=0.45,height=25,prompt_position="bottom"} layout_strategy=vertical', group = "Telescope color names", }, { mode = "n", key = "Tn", cmd = ":Telescope notify theme=dropdown layout_config={width=0.75}", group = "Telescope notify", }, { mode = "n", key = "TN", cmd = ":Telescope noice theme=dropdown layout_config={width=0.75}", group = "Telescope Noice", }, { mode = "n", key = "Ti", cmd = function() telescope_paste_img() end, desc = "Find and Paste Image", }, { mode = "n", key = "ff", cmd = ":Telescope find_files find_command=rg,--ignore,--follow,--hidden,--files prompt_prefix=🔍", group = "Find files", }, { mode = "n", key = "fg", cmd = ":Telescope live_grep", group = "Live Grep" }, { mode = "n", key = "Tg", cmd = ':Telescope glyph theme=dropdown layout_config={width=0.45,height=35,prompt_position="bottom"} layout_strategy=vertical', group = "Telescope Glyph", }, { mode = "n", key = "fG", cmd = ':Telescope glyph theme=dropdown layout_config={width=0.45,height=35,prompt_position="bottom"} layout_strategy=vertical', group = "Glhph", }, { mode = "n", key = "fb", cmd = ":Telescope file_browser", group = "File browser" }, { mode = "n", key = "fr", cmd = ":Telescope oldfiles theme=dropdown layout_config={width=0.5}", group = "Oldfiles", }, { mode = "n", key = "hc", cmd = ":Telescope commands", group = "Commands", }, { mode = "n", key = "hv", cmd = ":Telescope vim_options", group = "Vim options", }, { mode = "n", key = "hk", cmd = ":Telescope keymaps", group = "Keymaps", }, { mode = "n", key = "hs", cmd = ":Telescope spell_suggest", group = "Spell suggest", }, { mode = "n", key = "ht", cmd = ":Telescope help_tags", group = "Help tags", }, { mode = "n", key = "hm", cmd = ":Telescope man_pages theme=dropdown layout_config={width=0.75}", group = "Man pages", }, { mode = "n", key = "sf", cmd = ":Telescope find_files find_command=rg,--ignore,--follow,--hidden,--files prompt_prefix=🔍", group = "Search files", }, { mode = "n", key = "sF", cmd = ":Telescope fidget", group = "Fidget" }, { mode = "n", key = "sg", cmd = ":Telescope live_grep", group = "Live grep" }, { mode = "n", key = "sh", cmd = ":Telescope command_history", group = "Command history" }, { mode = "n", key = "sm", cmd = ":Telescope man_pages", group = "Man pages" }, { mode = "n", key = "s/", cmd = ":Telescope search_history", group = "Search history" }, { mode = "n", key = "gc", cmd = ":Telescope git_commits", group = "Git commits" }, { mode = "n", key = "gf", cmd = ":Telescope git_files", group = "Git files" }, { mode = "n", key = "Tr", cmd = ":Telescope reloader", group = "Telescope reloader" }, } --}}} -- {{{ File Explorer Mappings (i guess) local file_explorer_mappings = { { mode = "n", key = "nt", cmd = ":NvimTreeToggle" }, { mode = "n", key = "nc", cmd = ":lua require('notify').dismiss()" }, { mode = "n", key = "D", cmd = ":Dotenv .env", group = "Dotenv" }, } -- }}} -- {{{ Misc Utilities Mappings local misc_utilities_mappings = { { mode = "n", key = "x", cmd = "!chmod +x %", group = "Make Executable" }, { mode = "n", key = "y", cmd = '"+', group = "System Yank" }, { mode = "v", key = "y", cmd = '"+', group = "System Yank" }, { mode = "n", key = "sc", cmd = ":nohls", group = "Search" }, } -- }}} -- {{{ Goto Preview Mappings local goto_preview_mappings = { { mode = "n", key = "gpc", cmd = ':lua require("goto-preview").close_all_win()', group = "Goto Preview" }, { mode = "n", key = "gpd", cmd = ':lua require("goto-preview").goto_preview_definition()', group = "Goto Preview", }, { mode = "n", key = "gpi", cmd = ':lua require("goto-preview").goto_preview_implementation()', group = "Goto Preview", }, } -- }}} -- {{{ Workspace Management Mappings local workspace_management_mappings = { { mode = "n", key = "wa", cmd = vim.lsp.buf.add_workspace_folder }, { mode = "n", key = "wr", cmd = vim.lsp.buf.remove_workspace_folder }, { mode = "n", key = "wl", cmd = function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, }, } -- }}} -- {{{ Noice Mappings local noice_mappings = { { mode = "n", key = "Nh", cmd = ":Noice telescope", group = "Noice" }, { mode = "n", key = "Nl", cmd = ":Noice last", group = "Noice" }, { mode = "n", key = "Nd", cmd = ":Noice dismiss", group = "Noice" }, { mode = "n", key = "Ne", cmd = ":Noice errors", group = "Noice" }, { mode = "n", key = "Ns", cmd = ":Noice stats", group = "Noice" }, } -- }}} -- {{{ ODIS Mappings local odis_mappings = { { mode = "n", key = "dv", cmd = ':lua require("odis").show_documentation("vsplit")', group = "Vertical split", }, { mode = "n", key = "dh", cmd = ':lua require("odis").show_documentation("split")', group = "Split" }, { mode = "n", key = "db", cmd = ':lua require("odis").show_documentation("buffer")', group = "Buffer" }, { mode = "n", key = "dt", cmd = ':lua require("odis").show_documentation("tab")', group = "Tab" }, { mode = "n", key = "df", cmd = ':lua require("odis").show_documentation("float")', group = "Float" }, } -- }}} -- {{{ Diffview Mappings local diffview_mappings = { { mode = "n", key = "gdo", cmd = ":DiffviewOpen", group = "DiffviewOpen", }, { mode = "n", key = "gdf", cmd = ":DiffviewFileHistory %", group = "Git", }, { mode = "n", key = "gdh", cmd = ":DiffviewHistory", group = "Git", }, { mode = "n", key = "gdc", cmd = ":DiffviewClose", group = "Git", }, { mode = "n", key = "gdt", cmd = ":DiffviewToggleFiles", group = "Git", desc = "Toggle files view", }, { mode = "n", key = "gdr", cmd = ":DiffviewRefresh", desc = "Refresh diffview", group = "Git", }, } -- }}} --{{{ Custom Terminals local programs_map = { gg = { cmd = "lazygit", display_name = "lazygit", direction = "tab", hidden = true }, op = { cmd = "ipython", display_name = "ipython", direction = "vertical", hidden = true }, oP = { cmd = "ipython", display_name = "ipython-full", direction = "tab", hidden = true, }, oi = { cmd = "sudo iotop", display_name = "iotop", direction = "tab", hidden = true }, on = { cmd = "rmpc", display_name = "rmpc", direction = "tab", hidden = true }, oN = { cmd = "nvtop", display_name = "nvtop", direction = "tab", hidden = true }, ob = { cmd = "/usr/bin/btop", display_name = "btop", direction = "tab", hidden = true }, od = { cmd = "lazydocker", display_name = "lazydocker", direction = "tab", hidden = true }, } local temp local tbl = {} for key, value in pairs(programs_map) do temp = { cmd = function() term_toggle(term_factory(value)) end, key = "" .. key, group = value.group, mode = "n", desc = "Open " .. value.display_name, } table.insert(tbl, temp) end add_to_whichkey(tbl, { key = "o", group = "Open" }) function _G.set_terminal_keymaps() local opts = { buffer = 0 } map("t", "", [[]], opts) map("t", "", [[]], opts) end vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()") --}}} -- {{{ IMAGE local image_mappings = { { mode = "n", key = "id", cmd = ":lua require('image').disable()", desc = "Disable image rendering", }, { mode = "n", key = "ie", cmd = ":lua require('image').enable()", desc = "Enable image rendering", }, { mode = "n", key = "pi", cmd = function() telescope_paste_img() end, desc = "Find and Paste Image", }, } -- }}} --{{{ Groups add_to_whichkey(nil, { key = "a", group = "AnyJump" }) add_to_whichkey(nil, { key = "b", group = "Buffers" }) add_to_whichkey(nil, { key = "c", group = "Code" }) add_to_whichkey(nil, { key = "ca", group = "Code Actions" }) add_to_whichkey(nil, { key = "cc", group = "Calls" }) add_to_whichkey(nil, { key = "C", group = "CodeCompanion" }) add_to_whichkey(nil, { key = "cL", group = "LSP" }) add_to_whichkey(nil, { key = "d", group = "ODIS" }) add_to_whichkey(nil, { key = "f", group = "Find" }) add_to_whichkey(nil, { key = "g", group = "Git" }) add_to_whichkey(nil, { key = "gd", group = "DiffView" }) add_to_whichkey(nil, { key = "h", group = "Help" }) add_to_whichkey(nil, { key = "i", group = "Image" }) add_to_whichkey(nil, { key = "j", group = "AnyJump" }) add_to_whichkey(nil, { key = "N", group = "Noice" }) -- add_to_whichkey(nil, { key = "o", group = "Open" }) add_to_whichkey(nil, { key = "p", group = "Paste" }) add_to_whichkey(nil, { key = "pg", group = "Paste Git Raw" }) add_to_whichkey(nil, { key = "s", group = "Search" }) add_to_whichkey(nil, { key = "t", group = "Terminal" }) add_to_whichkey(nil, { key = "T", group = "Telescope" }) add_to_whichkey(nil, { key = "w", group = "Workspace" }) add_to_whichkey(nil, { key = "x", group = "Make Executable" }) add_to_whichkey(nil, { key = "y", group = "System Yank" }) add_to_whichkey(nil, { key = "0", group = "Horizontal Terminal" }) add_to_whichkey(nil, { key = "cP", group = "Python" }) --}}} --{{{ Whichkey Mappings local mappings_tables = { basic_mappings, buffer_navigation_mappings, terminal_mappings, lsp_mappings, code_companion_mappings, telescope_mappings, file_explorer_mappings, misc_utilities_mappings, goto_preview_mappings, workspace_management_mappings, noice_mappings, odis_mappings, diffview_mappings, image_mappings, } for _, mapping in ipairs(mappings_tables) do add_to_whichkey(map_from_table(mapping)) end add_to_whichkey(nil, { key = "dc", group = "Close" }) --}}}