visrc.lua (6304B)
1 require('vis') 2 require('plugins/myfiletype') 3 require('plugins/vis-commentary') 4 require('plugins/fzf-mru') 5 require('plugins/snippets') 6 require('plugins/ctags') 7 require('plugins/cursors') 8 9 leader = '<Space>' 10 11 -- from https://github.com/ninewise/dotfiles/blob/master/config/vis/visrc.lua 12 vis:command_register("fzf", function(argv, force, cur_win, selection, range) 13 local out = io.popen("fzf"):read() 14 if out then 15 if argv[1] then 16 vis:command(string.format('e "%s"', out)) 17 else 18 vis:command(string.format('open "%s"', out)) 19 end 20 vis:feedkeys("<vis-redraw>") 21 end 22 end, 'fuzzy file search') 23 24 vis:command_register("rg", function(argv, force, cur_win, selection, range) 25 local out = io.popen("irg"):read() 26 if out then 27 if argv[1] then 28 vis:command(string.format('e "%s"', out)) 29 else 30 vis:command(string.format('open "%s"', out)) 31 end 32 vis:feedkeys("<vis-redraw>") 33 end 34 end, 'fuzzy file-content search') 35 36 interpreters = { 37 ['python'] = '!ipython --no-banner -i "$vis_filepath"', 38 ['lua'] = '!lua -i $vis_filepath', 39 ['julia'] = '!julia -i $vis_filepath', 40 ['latex'] = '!tmux new-window -a "latexmk -pdf -pvc -f $vis_filepath"', 41 } 42 43 checkers = { 44 ['latex'] = '!tmux split-window -p 25 "chktex -q $vis_filepath | less"', 45 ['bash'] = '!tmux split-window -p 25 "shellcheck --color=never $vis_filepath | less"', 46 } 47 48 spellcheckers = { 49 ['latex'] = '!aspell -t -c $vis_filepath', 50 } 51 52 vis:command_register("prev", function(argv, force, cur_win, selection, range) 53 local file = io.popen('sed -n 2p ~/.mru') 54 local output = file:read() 55 local success, msg, status = file:close() 56 if status == 0 then 57 vis:feedkeys(string.format(":e '%s'<Enter>", output)) 58 else 59 vis:info('error ' .. tostring(status)) 60 end 61 vis:feedkeys('<vis-redraw>') 62 return true; 63 end, 'edit previous file') 64 65 vis.events.subscribe(vis.events.INIT, function() 66 -- global configuration options 67 vis:command('set theme adbasic') 68 69 vis:map(vis.modes.NORMAL, leader..'a', ':rg true<Enter>') 70 vis:map(vis.modes.NORMAL, leader..'A', ':rg<Enter>') 71 vis:map(vis.modes.NORMAL, leader..'B', ':e "$BIB"<Enter>') 72 vis:map(vis.modes.NORMAL, leader..'CC', ':e ~/.config/vis/visrc.lua<Enter>') 73 vis:map(vis.modes.NORMAL, leader..'CS', ':e ~/.config/vis/plugins/snippets.lua<Enter>') 74 vis:map(vis.modes.NORMAL, leader..'d', ':< date<Enter>') 75 vis:map(vis.modes.NORMAL, leader..'e', ':fzf true<Enter>') 76 vis:map(vis.modes.VISUAL, leader..'p', 77 function() 78 if vis.count then 79 vis:command(string.format(':|par %d', vis.count)) 80 else 81 vis:command(':|par') 82 end 83 end) 84 vis:map(vis.modes.NORMAL, leader..'ga', ':!git add "$vis_filepath"<Enter>') 85 vis:map(vis.modes.NORMAL, leader..'gc', ':!git commit -v -S<Enter>') 86 vis:map(vis.modes.NORMAL, leader..'gp', ':!git push<Enter>') 87 vis:map(vis.modes.NORMAL, leader..'l', ':set show-newline!<Enter>') 88 vis:map(vis.modes.NORMAL, leader..'m', ':!make<Enter>') 89 -- vis:map(vis.modes.NORMAL, leader..'m', ':!tmux split-window -p 25 "make"', 90 vis:map(vis.modes.NORMAL, leader..'n', ':set numbers!<Enter>') 91 vis:map(vis.modes.NORMAL, leader..'N', ':set relativenumbers!<Enter>') 92 vis:map(vis.modes.NORMAL, leader..'o', ':fzf<Enter>') 93 vis:map(vis.modes.NORMAL, leader..'p', ':< xclip -o<Enter>') 94 vis:map(vis.modes.NORMAL, leader..'P', ':< xclip -selection clipboard -o<Enter>') 95 vis:map(vis.modes.NORMAL, leader..'q', ':q<Enter>') 96 vis:map(vis.modes.NORMAL, leader..'Q', ':qa<Enter>') 97 vis:map(vis.modes.NORMAL, leader..'r', ':< scholarref ') 98 vis:map(vis.modes.NORMAL, leader..'t', ':!ctags -R . >/dev/null 2>&1 &<Enter>') 99 vis:map(vis.modes.NORMAL, leader..'T', ':e ~/doc/todo.md<Enter>') 100 vis:map(vis.modes.NORMAL, leader..'w', ':x/ +$/ c//<Enter>:w<Enter>') 101 vis:map(vis.modes.NORMAL, leader..'x', ':wq<Enter>') 102 vis:map(vis.modes.NORMAL, leader..'X', 103 function() -- mark todo item as done and append date 104 vis:feedkeys('f[c3l[x]<Escape>A **<Escape>h') 105 vis:command(':< printf "$(date +"%Y-%m-%d %H:%M")"') 106 vis:feedkeys('^') 107 end) 108 vis:map(vis.modes.VISUAL, leader..'y', ':> xsel -i<Enter>') 109 vis:map(vis.modes.VISUAL, leader..'Y', ':> xsel --clipboard -i<Enter>') 110 111 vis:map(vis.modes.NORMAL, '<F7>', ':!sent $vis_filepath &<Enter>') 112 vis:map(vis.modes.NORMAL, '<Tab><Tab>', '<vis-window-next>') 113 vis:map(vis.modes.NORMAL, leader..'<Tab>', ':prev<Enter>') 114 vis:map(vis.modes.NORMAL, leader..'%', ':vsplit<Enter>') 115 vis:map(vis.modes.NORMAL, leader..',', ':fzfmru<Enter>') 116 vis:map(vis.modes.NORMAL, '] ', 117 function() vis:feedkeys('o<Escape><Up>') end) 118 vis:map(vis.modes.NORMAL, '[ ', 119 function() vis:feedkeys('O<Escape><Down>') end) 120 end) 121 122 vis.events.subscribe(vis.events.WIN_OPEN, function(win) 123 -- per window configuration options 124 vis:command('set savemethod inplace') 125 vis:command('set show-tabs') 126 vis:command('set autoindent') 127 vis:command('set tabwidth 4') 128 vis:command('set colorcolumn 81') 129 130 -- complete from words in current file 131 vis:map(vis.modes.INSERT, '<C-x><C-n>', 132 function() 133 local tmpfile = '/tmp/vis-complete' 134 local fp = io.popen('vis-complete --word >'..tmpfile, 'w') 135 fp:write(vis.win.file:content(0, vis.win.file.size)) 136 fp:close() 137 local f = io.open(tmpfile, 'r') 138 local output = f:read() 139 vis:insert(output) 140 f:close() 141 vis:feedkeys("<vis-redraw>") 142 end) 143 144 -- file-type specific commands 145 if vis.win.syntax == 'latex' then 146 vis:command('set colorcolumn 0') 147 elseif vis.win.syntax == 'python' then 148 vis:command('set expandtab') 149 elseif vis.win.syntax == 'yaml' then 150 vis:command('set tabwidth 2') 151 vis:command('set expandtab') 152 end 153 154 -- file-type specific mappings 155 vis:map(vis.modes.NORMAL, leader..'i', 156 function() 157 local command = interpreters[vis.win.syntax] 158 if command then 159 vis:command(command) 160 else 161 vis:info("no interpreter found for this file type") 162 end 163 return true; 164 end) 165 vis:map(vis.modes.NORMAL, leader..'c', 166 function() 167 local command = checkers[vis.win.syntax] 168 if command then 169 vis:command(command) 170 else 171 vis:info("no syntax checker found for "..vis.win.syntax) 172 end 173 return true; 174 end) 175 vis:map(vis.modes.NORMAL, leader..'s', 176 function() 177 local command = spellcheckers[vis.win.syntax] 178 if command then 179 vis:command(':w') 180 vis:command(command) 181 vis:command(':e') 182 else 183 vis:info("no spell checker found for "..vis.win.syntax) 184 end 185 return true; 186 end) 187 188 end)