------------------------------------ --- REQUIRES ------------------------------------ require("vis") -- plugins require("build") -- use Trash directory instead, remove set_dir function require("backup") require("cursors") require("ctags") 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 ------------------------------------ --- VARIABLES ------------------------------------ local m = vis.modes ------------------------------------ --- FUNCTIONS ------------------------------------ local function map_cmd(mode, map, command, help) vis:map(mode, map, function() vis:command(command) end, help) end -- 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 local function map_keys(mode, map, keys, help) vis:map(mode, map, function() vis:feedkeys(keys) end, help) end ------------------------------------ --- COMMANDS ----------------------------------- 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 ------------------------------------- vis:map(m.NORMAL, " pf", function() vis:command("fzf") end, "Open file with fzf") vis:map(m.NORMAL, " pr", function() vis:command("fzfmru") 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") map_cmd(m.NORMAL, "!", "!bash", "Run bash") map_keys(m.NORMAL, " nl", ":\\&2 printf '\\2: %s\\\\n' \"$\\2\"/", "Print variable" ) map_keys(m.NORMAL, "\\v", 'V:x/^(\\s*)(.+)$/ c/\\1"$(\\2)"/', "Surround in variable") map_keys(m.NORMAL, ";|", "V:x/\\| / c/|\n\t/", "Wrap one-line multi pipe command") map_keys( m.NORMAL, "\\e", 'V:x/^(\\s*)(.+)$/ c/\\1[ "\\2" ] || exit 1/', "Condition exit if empty" ) map_cmd(m.NORMAL, "\\sc", "-/\\/,/\\/", "Expand to case") map_cmd(m.NORMAL, "\\sw", "-/\\/", "Expand to while") map_cmd(m.NORMAL, "\\sf", "-/\\/,/\\/", "Expand to for") map_cmd(m.NORMAL, "\\si", "-/\\/,/\\/", "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") end if win.syntax == "ansi_c" then map_keys(m.NORMAL, "\\a", "f,a hdwi", "Align table") end end)