summaryrefslogtreecommitdiff
path: root/.config/vis/plugins/ru-langmap.lua
diff options
context:
space:
mode:
authorseraphim <18ycm9tx@anonaddy.me>2026-08-27 11:50:43 +0700
committerseraphim <18ycm9tx@anonaddy.me>2026-08-27 11:50:43 +0700
commit6fc7f49449cb237e1aa37eb1025461fe3ea39589 (patch)
treeceebc8a65556830627a4546da57e30e72945175e /.config/vis/plugins/ru-langmap.lua
parentcc7b61a1496d25a100f012300c1121835a9f8177 (diff)
.
Diffstat (limited to '.config/vis/plugins/ru-langmap.lua')
-rw-r--r--.config/vis/plugins/ru-langmap.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/.config/vis/plugins/ru-langmap.lua b/.config/vis/plugins/ru-langmap.lua
new file mode 100644
index 0000000..0a81e35
--- /dev/null
+++ b/.config/vis/plugins/ru-langmap.lua
@@ -0,0 +1,67 @@
+-- ru-langmap: use QWERTY motions while Russian layout is active,
+-- and stop Ctrl/Alt+arrows / Shift+Enter from leaking into the buffer.
+-- No upstream plugin exists for this, so this is a local one.
+
+local M = {}
+
+local function modes(...)
+ return { ... }
+end
+
+-- terminal keys the editor has no bindings for
+function M.stray_keys()
+ local nop = function() end
+ for _, mode in ipairs(modes(vis.modes.NORMAL, vis.modes.VISUAL, vis.modes.OPERATOR_PENDING)) do
+ vis:map(mode, "<C-Left>", "b")
+ vis:map(mode, "<C-Right>", "w")
+ vis:map(mode, "<M-Left>", "b")
+ vis:map(mode, "<M-Right>", "w")
+ vis:map(mode, "<M-Up>", "<vis-nop>")
+ vis:map(mode, "<M-Down>", "<vis-nop>")
+ vis:map(mode, "<S-Enter>", "<Enter>")
+ end
+ for _, mode in ipairs(modes(vis.modes.INSERT, vis.modes.REPLACE, vis.modes.PROMPT)) do
+ vis:map(mode, "<C-Left>", nop)
+ vis:map(mode, "<C-Right>", nop)
+ vis:map(mode, "<M-Left>", nop)
+ vis:map(mode, "<M-Right>", nop)
+ vis:map(mode, "<M-Up>", nop)
+ vis:map(mode, "<M-Down>", nop)
+ vis:map(mode, "<S-Enter>", "<Enter>")
+ end
+end
+
+-- ЙЦУКЕН -> QWERTY for modal editing (insert mode stays untouched)
+function M.langmap()
+ local ru_en = {
+ q="й", w="ц", e="у", r="к", t="е", y="н", u="г", i="ш", o="щ", p="з",
+ ["["]="х", ["]"]="ъ",
+ a="ф", s="ы", d="в", f="а", g="п", h="р", j="о", k="л", l="д",
+ [";"]="ж", ["'"]="э",
+ z="я", x="ч", c="с", v="м", b="и", n="т", m="ь",
+ [","]="б", ["."]="ю",
+ }
+ local upper_ru = {
+ Й="Q", Ц="W", У="E", К="R", Е="T", Н="Y", Г="U", Ш="I", Щ="O", З="P",
+ Х="[", Ъ="]",
+ Ф="A", Ы="S", В="D", А="F", П="G", Р="H", О="J", Л="K", Д="L",
+ Ж=";", Э="'",
+ Я="Z", Ч="X", С="C", М="V", И="B", Т="N", Ь="M",
+ Б=",", Ю=".",
+ }
+ for _, mode in ipairs(modes(vis.modes.NORMAL, vis.modes.VISUAL, vis.modes.OPERATOR_PENDING)) do
+ for en, ru in pairs(ru_en) do
+ vis:map(mode, ru, en)
+ end
+ for ru, en in pairs(upper_ru) do
+ vis:map(mode, ru, en)
+ end
+ end
+end
+
+vis.events.subscribe(vis.events.INIT, function()
+ M.stray_keys()
+ M.langmap()
+end)
+
+return M