diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-21 16:06:25 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-21 16:06:25 +0200 |
commit | 10e12bbe481af7974739060f51210f7948fc1df9 (patch) | |
tree | 83722aca11901a5bf7ad433aac6a6b0ba05cf79a /config/essentials/vis/visrc.lua | |
parent | 4775688e796faece72c6621bcd94f6eb4ebac5ff (diff) | |
parent | c9cc72113521b793d1baa0d2f558b97478a6acf4 (diff) |
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'config/essentials/vis/visrc.lua')
-rw-r--r-- | config/essentials/vis/visrc.lua | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua index 1813888..7847784 100644 --- a/config/essentials/vis/visrc.lua +++ b/config/essentials/vis/visrc.lua @@ -1,73 +1,96 @@ ------------------------------------ ---- LIBRARIES +--- REQUIRES ------------------------------------ - -require('vis') -require('plugins/vis-cursors') -require('plugins/vis-title') -require('plugins/vis-snippets') +require("vis") + +-- plugins +require("build") +-- use Trash directory instead, remove set_dir function +require("backup") +require("cursors") +require("title") +require("commentary") +require("complete-line") +-- removed formatting because already fulfilled by format.lua +require("vis-go") +-- set height to 40% +require("fzf-open") +require("vis-ultisnips") +-- TODO: doesn't work when using with 'e|b' +-- require("yank-highlight") + +-- save position before formatting, use vis:redraw +local format = require("format") + +-- set height to 40% +local fzfmru = require("fzf-mru") +fzfmru.fzfmru_path = 'grep "^' .. os.getenv("PWD") .. '" | fzf' + + +-- todo: +-- c-scope +-- c-tags +-- ... +-- vis-goto, favor open-file-under-cursor +-- ... +-- ultisnips +-- ... +-- vis-yank-highlight ------------------------------------ ---- EVENTS +--- VARIABLES ------------------------------------ - -vis.events.subscribe(vis.events.INIT, function() - vis.options.ignorecase = true - vis.options.autoindent = true - vis.options.shell = "/bin/sh" - 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 -end) +local m = vis.modes ------------------------------------ --- FUNCTIONS ------------------------------------ -function map_cmd(mode, map, command, help) +local function map_cmd(mode, map, command, help) vis:map(mode, map, function() vis:command(command) end, help) end -function map_cmd_restore(mode, map, command, help) - vis:map(mode, map, function() - if (mode == vis.modes.INSERT) then - vis:feedkeys("<Escape>") - end - - vis:feedkeys("m") - vis:command(command) - vis:feedkeys("M") +-- 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 - if (mode == vis.modes.INSERT) then - vis:feedkeys("i") - end +local function map_keys(mode, map, keys, help) + vis:map(mode, map, function() + vis:feedkeys(keys) end, help) end ------------------------------------ ---- VARIABLES ------------------------------------- - -local m = vis.modes - ------------------------------------- --- COMMANDS ------------------------------------- +----------------------------------- -vis:command_register("Q", function(argv, force, win, selection, range) +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, "<C-p>", function() vis:command("fzf") end, "Open file with fzf") + + +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)") @@ -79,7 +102,32 @@ vis:map(m.NORMAL, " eh", function() vis:command("!lowdown $vis_filepath > ${vis_filepath%.md}.html") vis:info("exported.") end, "Export markdown to html") -vis:map(m.NORMAL, " nl", function() vis:feedkeys(":<seq -f '%0.0f. ' 1 ") end, "Insert numbered list") +map_keys(m.NORMAL, " nl", ":<seq -f '%0.0f. ' 1 ", "Insert numbered list") -- select markdown list element: ,x/^(\d+\.|[-*])\s+.+\n(^ .+\n)*/ + +------------------------------------ +--- EVENTS +------------------------------------ + +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) +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 +end) |