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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
--[=[ Helpers ]=]--
keys = {}
setmetatable(keys,
{
__index = function (table, index)
local mod, key = index:match("^(.*)_"), index:match("[^_]*$")
if mod == nil then
local upperkey = key:upper()
if upperkey == "ESCAPE" then key = "<Esc>"
elseif upperkey == "PIPE" then key = "|"
elseif #key > 1 then key = "<" .. key .. ">"
end
return key
end
mod = mod:upper()
if mod == "SHIFT" then key = "<S-" .. key .. ">"
elseif mod == "CONTROL" then key = "<C-" .. key .. ">"
elseif mod == "ALT" then key = "<M-" .. key .. ">"
elseif mod == "SUPER" then key = "<D-" .. key .. ">"
elseif mod ~= nil then error("Unknown key modifier \"" .. mod .. "\"!")
end
return key
end
})
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(map.keys,
{
__index = function (table, index)
table.rhs = table.rhs .. keys[index]
return table
end,
__call = function (table, ...)
return vim.keymap.set(table.lhs, table.rhs, ...)
end
})
local function icommand(command)
return keys.Control_o .. command .. keys.Return
end
--[=[ Mappings ]=]--
-- Quality of life
-- Tab navigation
map.n.Alt_p("gt")
map.n.Alt_o("gT")
map.i.Alt_p(keys.Control_o .. "gt")
map.i.Alt_o(keys.Control_o .. "gT")
map.t.Alt_p("<C-\\><C-N>gt")
map.t.Alt_o("<C-\\><C-N>gT")
-- Split navigation
local function windownav(letter) return keys.Control_w .. letter end
map.n.Control_l(windownav("l"))
map.n.Control_h(windownav("h"))
map.n.Control_j(windownav("j"))
map.n.Control_k(windownav("k"))
map.t.Control_l("<C-\\><C-o>" .. windownav("l") .. "<Esc>")
map.t.Control_h("<C-\\><C-o>" .. windownav("h") .. "<Esc>")
map.t.Control_j("<C-\\><C-o>" .. windownav("j") .. "<Esc>")
map.t.Control_k("<C-\\><C-o>" .. windownav("k") .. "<Esc>")
-- Ctrl-S, Ctrl-A, Ctrl-C, Ctrol-X
map.i.Control_s(icommand(":w"))
map.i.Control_a(keys.Escape .. "ggVG")
map.n.Control_s(":w" .. keys.Enter)
map.n.Control_a("ggVG")
map.x.Control_c('"+y')
map.x.Control_d('"+d')
-- Undo/redo
map.i.Control_r(keys.Control_o .. keys.Control_r)
map.i.Control_u(keys.Control_o .. "u")
-- Backspace
map.ic.Control_h(keys.Control_w)
map.ic.Control_BS(keys.Control_w)
-- Move lines
map.n.Alt_j(":m+1" .. keys.Enter)
map.n.Alt_k(":m-2" .. keys.Enter)
map.x.Alt_j(":m '>+1<CR>gv=gv")
map.x.Alt_k(":m '<-2<CR>gv=gv")
-- Special
map.n.Pipe(":tabnew | ter lazygit<CR>")
map.n.F6(function()
if vim.g.colors_name == "gruvbox" then
vim.o.spell = true
vim.cmd("colorscheme darkblue")
else
vim.o.spell = false
vim.cmd("colorscheme gruvbox")
end
end)
--[=[ Abbreviations ]=]--
vim.cmd("cnoreabbrev x wa \\| qa!")
|