local keymap = vim.api.nvim_set_keymap local opts = { noremap = true, silent = true } local mappings = { n = { ["nh"] = ":nohl", ["sv"] = "s", ["sh"] = "v", ["se"] = "=", ["sx"] = ":close", -- nvim-tree ["e"] = ":NvimTreeToggle", ["cf"] = ":NvimTreeCollapse", -- lsp ["ls"] = ":lspstop", ["lo"] = ":lspstart", -- move between buffers [""] = "h", [""] = "j", [""] = "k", [""] = "l", ["ff"] = "Telescope find_files", ["fw"] = "Telescope live_grep", ["fc"] = "Telescope grep_string", ["th"] = "Themery", ["sm"] = ":MaximizerToggle" }, x = { ["J"] = ":move '>+1gv-gv", ["K"] = ":move '<-2gv-gv", [""] = ":move '>+1gv-gv", [""] = ":move '<-2gv-gv", }, i = { ["c-j"] = [[lua require('copilot').accept()]], [""] = "", }, } for mode, mode_mappings in pairs(mappings) do for key, mapping in pairs(mode_mappings) do if type(mapping) == "function" then keymap(mode, key, "lua " .. mapping() .. "<>", opts) elseif type(mapping) == "table" then keymap(mode, key, mapping[1], mapping[2] or opts) else keymap(mode, key, mapping, opts) end end end