local keymap = vim.api.nvim_set_keymap local opts = { noremap = true, silent = true } local mappings = { n = { -- highlighting ["nh"] = ":nohl", -- move between buffers [""] = "h", [""] = "j", [""] = "k", [""] = "l", -- open and close buggers ["sv"] = "s", ["sh"] = "v", ["se"] = "=", ["sx"] = ":close", -- nvim-tree ["e"] = ":NvimTreeFindFileToggle", ["cf"] = ":NvimTreeCollapse", -- LSP ["ls"] = ":lspstop", ["lo"] = ":lspstart", -- Telescope ["ff"] = "Telescope find_files", ["fw"] = "Telescope live_grep", ["fc"] = "Telescope grep_string", ["th"] = "Themery", ["sm"] = ":MaximizerToggle", -- FTerm ["h"] = "FTermToggle", -- Harpoon ["a"] = "HarpoonToggleFile", [""] = "HarpoonUI", ["c"] = "HarpoonClear", -- Formating ["fm"] = "Format", -- Disable help menu [""] = "", }, x = { [""] = ":move '>+1gv-gv", [""] = ":move '<-2gv-gv", }, i = { [""] = { 'copilot#Accept("")', expr = true }, [""] = "", ["C-BS"] = "HarpoonRemove", -- Disable help menu [""] = "", }, t = { ["C-h"] = ":FTermClose", }, } for mode, mode_mappings in pairs(mappings) do for key, mapping in pairs(mode_mappings) do if type(mapping) == "function" then -- For direct Lua function calls; ensure your function returns a string command keymap(mode, key, "lua " .. mapping() .. "", opts) elseif type(mapping) == "table" and mapping.expr then -- For expression mappings, like for copilot local expr_opts = vim.tbl_extend("force", opts, { expr = true }) keymap(mode, key, mapping[1], expr_opts) elseif type(mapping) == "table" then -- For mappings that have their options specified directly keymap(mode, key, mapping[1], mapping[2] or opts) else -- For simple string command mappings keymap(mode, key, mapping, opts) end end end