-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.lua
More file actions
44 lines (37 loc) · 1.1 KB
/
util.lua
File metadata and controls
44 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local M = {}
--- Get my autocommand group from one spot only, easy to change later.
M.group = vim.api.nvim_create_augroup("markmacode", { clear = true })
--- A more human readable and configurable mapping function
--- designed after the lazy.nvim way. Each map entry defaults
--- to normal mode.
---
--- @param maps table map entries in the format of lazy.vim `keys`
--- @param extra_opts table|nil keymap opts to apply on every map in `maps`
function M.keys(maps, extra_opts)
extra_opts = extra_opts or {}
for _, value in ipairs(maps) do
M._map(value, extra_opts)
end
end
function M._map(table, extra_opts)
local lhs = table[1]
local rhs = table[2]
local mode = table.mode or "n"
local opts = {}
-- only send actual keymap opts to `opts`
for key, value in pairs(table) do
if type(key) ~= "number" and key ~= "mode" then
opts[key] = value
end
end
-- apply the extra opts too, overriding if needed
for key, value in pairs(extra_opts) do
if key == "mode" then
mode = value
else
opts[key] = value
end
end
vim.keymap.set(mode, lhs, rhs, opts)
end
return M