Summary Files Commits Branches @commit @diff @stats
path: root / lua / mappings.lua
blob: 2fd6830d110ece0b17b2b566f900668aabf75046 (plain) (blame)
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
45
--[=[ Helpers ]=]--

map = { keys = { lhs = {}, rhs = "" } }
setmetatable(map,
{
	__index = function (table, index)
		table.keys.lhs = {}
		table.keys.rhs = ""
		for i = 1, index:len() do
			table.keys.lhs[i] = index:sub(i, i)
		end
		return table.keys
	end
})
setmetatable(rawget(map, "keys"),
{
	__index = function (table, index)
		local mod, key = index:match("^(.*)_"), index:match("[^_]*$")
		if mod == nil then 
			if #key > 1 then
				key = "<" .. key .. ">"
			end
			table.rhs = table.rhs .. key
			return table
		end
		mod = mod:upper()

		if     mod == "SHIFT"   then table.rhs = table.rhs .. "<S-" .. key .. ">"
		elseif mod == "CONTROL" then table.rhs = table.rhs .. "<C-" .. key .. ">"
		elseif mod == "ALT"     then table.rhs = table.rhs .. "<M-" .. key .. ">"
		elseif mod == "SUPER"   then table.rhs = table.rhs .. "<D-" .. key .. ">"
		elseif mod ~= nil       then error("Unknown key modifier \"" .. mod .. "\"!")
		end

		return table
	end,
	__call = function (table, ...)
		return vim.keymap.set(table.lhs, table.rhs, ...)
	end
})

--[=[ Mappings ]=]--

map.n.Alt_p("gt")
map.n.Alt_o("gT")