Summary Files Commits Branches @commit @diff @stats
path: root / nvim / .nvim / lua / mappings.lua
diff options
context:
space:
mode:
Commitc9ca8a09dc3a5e421c50dc3cfa16c573a3e87135 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-11-01 22:51:04 +0200
Committer
 Syndamia <kamen@syndamia.com>
2026-11-01 22:51:18 +0200
Filesec3e06cdc9099838406b918f5b9347eee46adf88 /nvim/.nvim/lua/mappings.lua
.files-main.tar
.files-main.tar.gz
.files-main.zip
Parent72d71324e1063d4d7402180e846aeff3056ba177 (diff)
feat(nvim): Implement nvim config HEAD main
Latest version from https://git.syndamia.com/conf/anderson (and formerly https://gitlab.com/Syndamia/anderson). Not edited in 7 months.
1 files changed, 127 insertions, 0 deletions
-rw-r--r--nvim/.nvim/lua/mappings.lua127
diff --git a/nvim/.nvim/lua/mappings.lua b/nvim/.nvim/lua/mappings.lua
new file mode 100644
index 0000000..4257e06
--- /dev/null
+++ b/nvim/.nvim/lua/mappings.lua
@@ -0,0 +1,127 @@
+--[=[ Helpers ]=]--
+
+keys = {}
+setmetatable(keys,
+{
+ __index = function (table, index)
+ local mod, key = index:match("^(.*)_"), index:match("[^_]*$")
+ if mod == nil then
+ if #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
+map.t["Esc><Esc"]("<C-\\><C-N>")
+map.n.Control_t(":topl sp | ter" .. keys.Enter)
+map.n.Control_c("<C-I>")
+
+-- 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_x('"+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["|"](":tabnew | ter lazygit<CR>", { silent = true })
+map.n.F6(function()
+ vim.cmd("set spell!")
+end)
+
+local telescope = require('telescope.builtin')
+vim.keymap.set('n', 'ff', telescope.find_files)
+vim.keymap.set('n', 'fg', telescope.live_grep)
+vim.keymap.set('n', 'fb', telescope.buffers)
+vim.keymap.set('n', 'fc', telescope.git_commits)
+
+--[=[ Abbreviations ]=]--
+vim.cmd("cnoreabbrev x wa \\| qa!")
+
+--[=[ Language mappings ]=]--
+vim.opt.langmap = {
+ -- Lowercase mappings
+ "аa", "бb", "вw", "гg", "дd", "еe", "жv", "зz", "иi", "йj", "кk", "лl", "мm", "нn",
+ "оo", "пp", "рr", "сs", "тt", "уu", "фf", "хh", "цc", "ч`", "ш[", "щ]", "ъy", "ьx", "ю\\", "яq",
+
+ --, Uppercase, mappings
+ "АA", "БB", "ВW", "ГG", "ДD", "ЕE", "ЖV", "ЗZ", "ИI", "ЙJ", "КK", "ЛL", "МM", "НN",
+ "ОO", "ПP", "РR", "СS", "ТT", "УU", "ФF", "ХH", "ЦC", "Ч~", "Ш[", "Щ]", "ЪY", "ЬX", "Ю|", "ЯQ",
+}