local fterm = require('FTerm') local keymap = vim.api.nvim_set_keymap local opts = { noremap = true, silent = true } local api = vim.api -- Custom commands api.nvim_create_user_command('FTermToggle', fterm.toggle, { bang = true }) api.nvim_create_user_command('FTermClose', fterm.close, { bang = 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"] = ":NvimTreeToggle", ["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"] = "HarpoonAdd", [""] = "HarpoonUI" }, x = { [""] = ":move '>+1gv-gv", [""] = ":move '<-2gv-gv", }, i = { [""] = { 'copilot#Accept("")', expr = true }, [""] = "", }, t = { ["A-l"] = "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