Something went wrong. Try again.
Neovim config
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113--[[ A wrapper around vim.keymap.set for conveniently defining keybinds. Originally written by glepnir (https://github.com/glepnir/cosynvim/blob/main/lua/core/keymap.lua).--]]
local M = {}local opts = {}
function opts:new(instance) instance = instance or { options = { silent = true, nowait = false, expr = false, remap = false, }, } setmetatable(instance, self) self.__index = self return instanceend
function M.nosilent(opt) return function() opt.silent = false endend
function M.nowait(opt) return function() opt.nowait = true endend
function M.expr(opt) return function() opt.expr = true endend
function M.remap(opt) return function() opt.remap = true endend
function M.new_opts(...) local args = { ... } local o = opts:new()
if #args == 0 then return o.options end
for _, arg in pairs(args) do if type(arg) == "string" then o.options.desc = arg elseif type(arg) == "number" then o.options.buffer = arg else arg(o.options)() end end return o.optionsend
function M.cmd(str) return "<Cmd>" .. str .. "<CR>"end
-- visual modefunction M.cu(str) return "<C-u><cmd>" .. str .. "<CR>"end
local function keymap_set(mode, tbl) vim.validate("tbl", tbl, "table") local len = #tbl
assert(len >= 2, "Keymap must have rhs")
local options = len == 3 and tbl[3] or M.new_opts()
vim.keymap.set(mode, tbl[1], tbl[2], options)end
local function map(mode) return function(tbl) vim.validate("tbl", tbl, "table") if type(tbl[1]) == "table" then for _, v in pairs(tbl) do keymap_set(mode, v) end else keymap_set(mode, tbl) end endend
M.nmap = map("n")M.imap = map("i")M.cmap = map("c")M.vmap = map("v")M.xmap = map("x")M.tmap = map("t")M.smap = map("s")M.ismap = map({ "i", "s" })M.nxmap = map({ "n", "x" })M.xomap = map({ "x", "o" })
return M