summaryrefslogtreecommitdiff
path: root/config/essentials/vis/visrc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'config/essentials/vis/visrc.lua')
-rw-r--r--config/essentials/vis/visrc.lua105
1 files changed, 63 insertions, 42 deletions
diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua
index e35b436..3bfe594 100644
--- a/config/essentials/vis/visrc.lua
+++ b/config/essentials/vis/visrc.lua
@@ -8,6 +8,7 @@ require("build")
-- use Trash directory instead, remove set_dir function
require("backup")
require("cursors")
+require("ctags")
require("title")
require("commentary")
require("complete-line")
@@ -26,7 +27,6 @@ local format = require("format")
local fzfmru = require("fzf-mru")
fzfmru.fzfmru_path = 'grep "^' .. os.getenv("PWD") .. '" | fzf'
-
-- todo:
-- c-scope
-- c-tags
@@ -52,8 +52,8 @@ local function map_cmd(mode, map, command, help)
end, help)
end
--- TOOD: use window selection to restore position
-local function wrap_restore(f, ...)
+-- Store and pop position with command ran in between
+local function wrap_pos_restore(f, ...)
local pos = vis.win.selection.pos
f(...)
vis.win.selection.pos = pos
@@ -70,7 +70,7 @@ end
-----------------------------------
vis:command_register("make", function()
- vis:command("!make && head -n 1")
+ vis:command("!make; head -n 1")
end, "make")
vis:command_register("Q", function()
vis:command("qa!")
@@ -83,29 +83,27 @@ end, "Remove trailing whitespace")
--- MAPPINGS
-------------------------------------
-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)")
-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")
-
-vis:map(m.NORMAL, " eh", function()
- 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")
-
--- select markdown list element: ,x/^(\d+\.|[-*])\s+.+\n(^ .+\n)*/
+vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- luacheck: no unused args
+ map_cmd(m.NORMAL, " pf", "fzf", "Open file with fzf")
+ map_cmd(m.NORMAL, " pr", "fzfmru", "Open file with fzf")
+
+ vis:map(m.NORMAL, " r", function()
+ wrap_pos_restore(vis.command, vis, "e $vis_filepath")
+ end, "Reload active file")
+ vis:map(m.NORMAL, "=", format.apply, "Format active file")
+ map_cmd(m.NORMAL, "<M-m>", "make", "Run 'make'")
+ 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, "!", "!bash", "Run bash")
+ map_keys(m.NORMAL, " y", '"+y', "Copy to system clipboard")
+ map_keys(m.VISUAL, " y", '"+y', "Copy to system clipboard")
+ map_keys(m.NORMAL, " nl", ":<seq -f '%0.0f. ' 1 ", "Insert numbered list")
+ map_keys(m.NORMAL, "<M-S-Down>", "ddp", "Move line down")
+ map_keys(m.NORMAL, "<M-S-Up>", "ddkP", "Move line up") -- Doesn't work at end of file
+end)
------------------------------------
--- EVENTS
@@ -120,33 +118,56 @@ vis.events.subscribe(vis.events.INIT, function()
end)
vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- luacheck: no unused args
+ -- automatically cd in parent dir of file
+ vis:command_register("cdp", function()
+ if win.file and win.file.path then
+ local dir = win.file.path:match(".*/")
+ vis:command("cd " .. dir)
+ end
+ end, "Cd to parent dir of file")
+
win.options.relativenumbers = true
+ if win.syntax then
+ vis:info(win.syntax)
+ end
+
+ -- FILETYPE OPTIONS
if win.syntax == "bash" then
map_keys(
m.NORMAL,
- ";p",
+ "\\p",
"V:x/^(\\s*)(.+)$/ c/\\1>\\&2 printf '\\2: %s\\\\n' \"$\\2\"/<Enter><Escape>",
"Print variable"
)
+ map_keys(m.NORMAL, "\\v", 'V:x/^(\\s*)(.+)$/ c/\\1"$(\\2)"/<Enter><Escape>', "Surround in variable")
+ map_keys(m.NORMAL, "\\|", "V:x/\\| / c/|\n\t/<Enter><Escape>", "Wrap one-line multi pipe command")
map_keys(
m.NORMAL,
- ";v",
- "V:x/^(\\s*)(.+)$/ c/\\1\"$(\\2)\"/<Enter><Escape>",
- "Surround in variable"
- )
- map_keys(
- m.NORMAL,
- ";|",
- "V:x/\\| / c/|\n\t/<Enter><Escape>",
- "Wrap one-line multi pipe command"
- )
- map_keys(
- m.NORMAL,
- ";e",
- "V:x/^(\\s*)(.+)$/ c/\\1[ \"\\2\" ] || exit 1/<Enter><Escape>",
+ "\\e",
+ 'V:x/^(\\s*)(.+)$/ c/\\1[ "\\2" ] || exit 1/<Enter><Escape>',
"Condition exit if empty"
)
+ map_cmd(m.NORMAL, "\\sc", "-/\\<case\\>/,/\\<esac\\>/", "Expand to case")
+ map_cmd(m.NORMAL, "\\sw", "-/\\<while/,/\\<done\\>/", "Expand to while")
+ map_cmd(m.NORMAL, "\\sf", "-/\\<for\\>/,/\\<done\\>/", "Expand to for")
+ map_cmd(m.NORMAL, "\\si", "-/\\<if\\>/,/\\<fi\\>/", "Expand to if")
+ end
+
+ if win.syntax == "markdown" then
+ vis:map(m.NORMAL, "\\h", function()
+ vis:command("!lowdown $vis_filepath > ${vis_filepath%.md}.html")
+ vis:info("exported.")
+ end, "Export markdown to html")
+ map_cmd(m.NORMAL, "\\sl", "-+x/(\\d+|[-*])\\s+.+\n/", "Expand to list item")
+ map_cmd(m.NORMAL, "\\sh", "-/^#+/,/^#+/-", "Expand to header")
+ -- select header block by name
+ -- ,x/^# Planning\n([^#]|\n)+
+ win.options.tabwidth = 2
+ win.options.expandtab = true
+ end
+ if win.syntax == "ansi_c" then
+ map_keys(m.NORMAL, "\\a", "f,a <Escape>hdw<S-Tab>i<Tab><Escape>", "Align table")
end
end)