diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-20 23:46:00 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-20 23:46:00 +0200 |
commit | a0f45aece21a6280633023ec84f60eb0d5e0849a (patch) | |
tree | 3d8d0e8294e84606ffea97e524be1cb94cdf8cb4 /config/essentials/vis/visrc.lua | |
parent | 2f8816e47e0797083a667d5cf7e778940dd1f789 (diff) |
checkpoint
Diffstat (limited to 'config/essentials/vis/visrc.lua')
-rw-r--r-- | config/essentials/vis/visrc.lua | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua index 3a9ff1d..60162bc 100644 --- a/config/essentials/vis/visrc.lua +++ b/config/essentials/vis/visrc.lua @@ -1,71 +1,83 @@ ------------------------------------ --- LIBRARIES ------------------------------------ -require('vis') +require("vis") -- plugins require("build") require("backup") require("cursors") require("title") +require("commentary") +require("complete-line") +local format = require("format") -vis:command_register("make", function() vis:communicate() end, "make") +-- todo: +-- c-scope +-- c-tags ------------------------------------ ---- FUNCTIONS +--- VARIABLES ------------------------------------ -local map_cmd = function(mode, map, command, help) - vis:map(mode, map, function() vis:command(command) end, help) -end - -local map_cmd_restore = function(mode, map, command, help) - vis:map(mode, map, function() - if (mode == vis.modes.INSERT) then vis:feedkeys("<Escape>") end +local m = vis.modes - vis:feedkeys("m") - vis:command(command) - vis:feedkeys("M") +------------------------------------ +--- FUNCTIONS +------------------------------------ - if (mode == vis.modes.INSERT) then vis:feedkeys("i") end - end, help) +local function map_cmd(mode, map, command, help) + vis:map(mode, map, function() + vis:command(command) + end, help) end -local map_keys = function(mode, map, keys, help) - vis:map(mode, map, function() vis:feedkeys(keys) end, help) +-- TOOD: use window selection to restore position +local function wrap_restore(f, ...) + local pos = vis.win.selection.pos + f(...) + vis.win.selection.pos = pos end ------------------------------------- ---- VARIABLES ------------------------------------- - -local m = vis.modes +local function map_keys(mode, map, keys, help) + vis:map(mode, map, function() + vis:feedkeys(keys) + end, help) +end ------------------------------------ --- COMMANDS ----------------------------------- -vis:command_register("Q", function() vis:command("qa!") end, "Quit all") -vis:command_register("delws", - function() vis:command("x/[ \t]+$|^[ \t]+$/d") end, - "Remove trailing whitespace") +vis:command_register("make", function() + vis:command("!make && head -n 1") +end, "make") +vis:command_register("Q", function() + vis:command("qa!") +end, "Quit all") +vis:command_register("delws", function() + vis:command("x/[ \t]+$|^[ \t]+$/d") +end, "Remove trailing whitespace") ------------------------------------- --- MAPPINGS ------------------------------------- -map_cmd_restore(m.NORMAL, " r", "e $vis_filepath", "Reload active file") +vis:map(m.NORMAL, " r", function() + wrap_restore(vis.command, vis, "e $vis_filepath") +end, "Reload active file") + +vis:map(m.NORMAL, "=", format.apply, "Format active file") map_cmd(m.NORMAL, " c", "e ~/.config/vis/visrc.lua", "Edit config file") map_cmd(m.NORMAL, " q", "q!", "Quit (force)") map_cmd(m.NORMAL, " s", "!doas vis $vis_filepath", "Edit as superuser") map_cmd(m.NORMAL, " w", "w", "Write") -map_cmd(m.NORMAL, " x", "!chmod u+x $vis_filepath", - "Make active file executable") +map_cmd(m.NORMAL, " x", "!chmod u+x $vis_filepath", "Make active file executable") vis:map(m.NORMAL, " eh", function() - vis:command("!lowdown $vis_filepath > ${vis_filepath%.md}.html") - vis:info("exported.") + vis:command("!lowdown $vis_filepath > ${vis_filepath%.md}.html") + vis:info("exported.") end, "Export markdown to html") map_keys(m.NORMAL, " nl", ":<seq -f '%0.0f. ' 1 ", "Insert numbered list") @@ -77,20 +89,26 @@ map_keys(m.NORMAL, " nl", ":<seq -f '%0.0f. ' 1 ", "Insert numbered list") ------------------------------------ vis.events.subscribe(vis.events.INIT, function() - vis.options.ignorecase = true - vis.options.autoindent = true - vis.options.shell = "/bin/sh" - local theme = "nord" - vis:command("set theme " .. theme) + vis.options.ignorecase = true + vis.options.autoindent = true + vis.options.shell = "/bin/sh" + local theme = "nord" + vis:command("set theme " .. theme) end) -vis.events.subscribe(vis.events.WIN_OPEN, - function(win) -- luacheck: no unused args - win.options.relativenumbers = true - - if win.syntax == "bash" then - map_keys(m.NORMAL, " v", - "V:x/^(\\s*)(.+)$/ c/\\1>\\&2 printf '\\2: %s\\\\n' \"$\\2\"/<Enter><Escape>", - "Print variable") - end +vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- luacheck: no unused args + win.options.relativenumbers = true + + if win.syntax == "bash" then + map_keys( + m.NORMAL, + " v", + "V:x/^(\\s*)(.+)$/ c/\\1>\\&2 printf '\\2: %s\\\\n' \"$\\2\"/<Enter><Escape>", + "Print variable" + ) + end + + vis:command_register("pipe", function() + vis:pipe(win.file, nil, "sed 's/.*/- &/'") + end, "pipe test") end) |