summaryrefslogtreecommitdiff
path: root/.config/vis/visrc.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/vis/visrc.lua')
-rw-r--r--.config/vis/visrc.lua169
1 files changed, 162 insertions, 7 deletions
diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua
index 2c78715..e62a46b 100644
--- a/.config/vis/visrc.lua
+++ b/.config/vis/visrc.lua
@@ -1,12 +1,167 @@
require('vis')
--- Auto-themed colors from wallust (palette derived from the wallpaper).
--- Falls back to a built-in theme if wallust hasn't generated one yet.
-local wallust = os.getenv('HOME') .. '/.cache/wallust/vis-theme.lua'
-if not pcall(dofile, wallust) then
- pcall(require, 'themes.solarized')
-end
+ -- config --
+-- global
+vis.events.subscribe(vis.events.INIT, function()
+ vis:command("set theme wallust")
+end)
+-- per-window
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
- vis:command('set number')
+ -- kdl: no ftdetect entry ships with vis
+ if win.file and win.file.name:match('%.kdl$') then win.syntax = 'kdl' end
+ vis:command("set tabwidth 2")
+ vis:command("set numbers true") vis:command("set relativenumbers true") vis:command("set autoindent true")
+ vis:command("set showspaces false")
+ vis:command("set showtabs false")
+ vis:command("set expandtab on")
+ vis:command("set shell /usr/bin/env sh")
+ vis:map(vis.modes.VISUAL," y", '"+y"')
+
+ -- system clipboard (wayland) via wl-copy / wl-paste
+ local function selected_text()
+ local win = vis.window
+ local sel = win and win.selection
+ if not sel then return nil end
+ return sel:save()
+ end
+ local function to_clipboard(text)
+ if not text or #text == 0 then return end
+ local p = io.popen("wl-copy", "w")
+ if p then p:write(text) p:close() end
+ end
+ local function from_clipboard()
+ local p = io.popen("wl-paste")
+ if not p then return end
+ local t = p:read("*a")
+ p:close()
+ return t
+ end
+ -- super+c (Ctrl+Insert): copy selection
+ vis:map(vis.modes.VISUAL, "<C-Insert>", function()
+ to_clipboard(selected_text())
+ end)
+ -- super+x (Shift+Delete): cut = copy selection then delete it
+ vis:map(vis.modes.VISUAL, "<S-Delete>", function()
+ to_clipboard(selected_text())
+ vis:feedkeys("x")
+ end)
+ -- super+v (Shift+Insert): paste from system clipboard
+ vis:map(vis.modes.INSERT, "<S-Insert>", function()
+ local t = from_clipboard()
+ if t then vis:insert(t) end
+ end)
+ vis:map(vis.modes.NORMAL, "<S-Insert>", function()
+ local t = from_clipboard()
+ if t then
+ vis:command("set paste on")
+ vis:insert(t)
+ vis:command("set paste off")
+ end
+ end)
+
+ vis:map(vis.modes.NORMAL, " fm", function()
+ vis:command("open .")
+ vis:feedkeys("<C-w>k")
+ vis:command("wq!")
+ end, "")
end)
+
+ -- plugins --
+
+-- modal
+local modal = require('plugins/vis-modal')
+-- vis-autoclose
+local autoclose = require('plugins/vis-autoclose')
+-- colorizer
+local colorizer = require('plugins/vis-colorizer')
+colorizer.three = false
+colorizer.six = true
+ -- complete-filename
+ local completefilename = require('plugins/complete-filename')
+
+ -- stray terminal keys: Ctrl/Alt+arrows, Shift+Enter
+ local nop = function() end
+ for _, mode in ipairs({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({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
+
+ -- russian layout: use QWERTY motions while Ru is active (normal/visual modes)
+ 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({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
+-- vis-lspc
+local lsp = require('plugins/vis-lspc')
+--lsp.ls_map.clangd = {
+-- formatting_options = {tabSize = 2, insertSpaces = false}
+--}
+lsp.ls_map.lua = {
+ name = 'lua-language-server',
+ cmd = 'lua-language-server',
+ settings = {
+ Lua = {diagnostics = { globals = {'vis'}}, telemetry = {enable = false}},
+ },
+ formatting_options = {tabSize = 2, insertSpaces = true},
+}
+-- python via pyright (npm) instead of pylsp
+lsp.ls_map.python = {
+ name = 'pyright-langserver',
+ cmd = 'pyright-langserver --stdio',
+ roots = {'pyproject.toml', 'setup.py', 'requirements.txt'},
+}
+-- markdown via marksman
+lsp.ls_map.markdown = {
+ name = 'marksman',
+ cmd = 'marksman',
+}
+-- yaml (not preconfigured by vis-lspc)
+lsp.ls_map.yaml = {
+ name = 'yaml-language-server',
+ cmd = 'yaml-language-server --stdio',
+}
+-- dockerfile (not preconfigured by vis-lspc)
+lsp.ls_map.dockerfile = {
+ name = 'docker-langserver',
+ cmd = 'docker-langserver --stdio',
+}
+
+-- gq: format buffer with the active language server
+vis:map(vis.modes.NORMAL, ' gq', function()
+ vis:command('lspc-format')
+end, 'LSP format')