2017-10-04 15:11:16 +02:00
|
|
|
-- load standard vis module, providing parts of the Lua API
|
2020-03-14 13:37:56 +01:00
|
|
|
|
|
|
|
-- get inspiration from: https://src.adamsgaard.dk/dotfiles/file/.config/vis/visrc.lua.html
|
|
|
|
|
2017-10-04 15:11:16 +02:00
|
|
|
require('vis')
|
|
|
|
require('plugins/complete-word')
|
|
|
|
require('plugins/myfiletype')
|
2018-10-08 13:51:36 +02:00
|
|
|
require('plugins/editorconfig/editorconfig')
|
2019-10-29 19:38:32 +01:00
|
|
|
require('plugins/vis-quickfix/quickfix')
|
2017-10-04 15:11:16 +02:00
|
|
|
|
|
|
|
vis.events.subscribe(vis.events.INIT, function()
|
|
|
|
-- Your global configuration options
|
2018-02-26 11:56:19 +01:00
|
|
|
vis:command('set escdelay 0')
|
|
|
|
vis:command('set tabwidth 4')
|
|
|
|
vis:command('set autoindent on')
|
|
|
|
vis:command('set theme dark-16')
|
2017-10-04 15:11:16 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
2017-11-29 17:29:06 +01:00
|
|
|
-- Your per window configuration options
|
2017-10-04 15:11:16 +02:00
|
|
|
vis:command('set show-tabs on')
|
|
|
|
vis:command('set number')
|
|
|
|
end)
|
|
|
|
|
2019-12-07 00:06:27 +01:00
|
|
|
vis:map(vis.modes.NORMAL, "<Escape>", function()
|
|
|
|
if vis.count then
|
|
|
|
vis.count = nil
|
|
|
|
else
|
2020-04-15 12:36:18 +02:00
|
|
|
vis:feedkeys("<vis-selections-remove-all>")
|
2019-12-07 00:06:27 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-11-17 17:37:24 +01:00
|
|
|
vis:command_register("fzf", function(argv, force, cur_win, selection, range)
|
2017-10-04 15:11:16 +02:00
|
|
|
local out = io.popen("fzf"):read()
|
|
|
|
if out then
|
2017-11-17 17:37:24 +01:00
|
|
|
if argv[1] then
|
2018-02-26 11:56:19 +01:00
|
|
|
vis:command(string.format('e "%s"', out))
|
2017-11-29 17:29:06 +01:00
|
|
|
else
|
2018-02-26 11:56:19 +01:00
|
|
|
vis:command(string.format('open "%s"', out))
|
2017-11-17 17:37:24 +01:00
|
|
|
end
|
|
|
|
vis:feedkeys("<vis-redraw>")
|
2017-10-04 15:11:16 +02:00
|
|
|
end
|
2019-12-07 00:06:27 +01:00
|
|
|
end, 'fuzzy file search')
|
2017-11-17 17:37:24 +01:00
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";l", function()
|
|
|
|
vis:command('fzf')
|
|
|
|
end)
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";o", function()
|
|
|
|
vis:command('fzf true')
|
2017-10-04 15:11:16 +02:00
|
|
|
end)
|
2017-10-20 10:00:58 +02:00
|
|
|
|
2020-03-14 13:37:56 +01:00
|
|
|
vis:map(vis.modes.NORMAL, ";r", function()
|
2020-04-15 00:37:50 +02:00
|
|
|
local choice = io.popen('tac < ' .. vis.win.file.path .. ' | fzf'):read()
|
2020-03-14 13:37:56 +01:00
|
|
|
if choice then
|
|
|
|
local line = vis.win.selection.line
|
|
|
|
table.insert(vis.win.file.lines, line + 1, choice)
|
|
|
|
vis.win.selection:to(line + 1, 0)
|
|
|
|
end
|
|
|
|
vis:feedkeys("<vis-redraw>")
|
|
|
|
end, 'fuzzy line copy')
|
|
|
|
|
2017-10-20 10:00:58 +02:00
|
|
|
vis:map(vis.modes.NORMAL, ";;", "<vis-window-next>")
|
2018-02-26 11:56:19 +01:00
|
|
|
|
2018-10-08 13:39:26 +02:00
|
|
|
interactives = {
|
2020-03-14 13:37:56 +01:00
|
|
|
["python"] = "!python -i ",
|
|
|
|
["haskell"] = "!stack ghci ",
|
|
|
|
["lithaskell"] = "!stack ghci ",
|
|
|
|
["latex"] = "!tectonic ",
|
2018-10-08 13:39:26 +02:00
|
|
|
}
|
2019-06-03 10:22:56 +02:00
|
|
|
|
2018-02-26 11:56:19 +01:00
|
|
|
vis:map(vis.modes.NORMAL, ";i", function()
|
2018-10-08 13:39:26 +02:00
|
|
|
local command = interactives[vis.win.syntax]
|
|
|
|
if command then
|
2020-03-14 13:37:56 +01:00
|
|
|
vis:command(command.."'"..vis.win.file.name.."'")
|
2018-06-28 13:46:23 +02:00
|
|
|
end
|
|
|
|
end)
|
2018-10-08 13:39:26 +02:00
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";w", function()
|
|
|
|
vis:command('set theme light-16')
|
|
|
|
end)
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";b", function()
|
|
|
|
vis:command('set theme dark-16')
|
|
|
|
end)
|
2019-03-11 10:42:41 +01:00
|
|
|
|
|
|
|
vis:map(vis.modes.INSERT, '<Backspace>', function()
|
|
|
|
local tabwidth = 4
|
2019-06-04 21:40:57 +02:00
|
|
|
local single_selection = false
|
2019-03-11 10:42:41 +01:00
|
|
|
for selection in vis.win:selections_iterator() do
|
2019-06-04 21:40:57 +02:00
|
|
|
if single_selection then
|
2019-10-29 19:38:32 +01:00
|
|
|
single_selection = false
|
2019-03-11 10:42:41 +01:00
|
|
|
break
|
|
|
|
end
|
2019-06-04 21:40:57 +02:00
|
|
|
single_selection = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local to_stop = (vis.win.selection.col - 1) % tabwidth
|
|
|
|
if to_stop == 0 then
|
|
|
|
to_stop = tabwidth
|
|
|
|
end
|
|
|
|
|
|
|
|
if single_selection and to_stop > 1 and vis.win.file:content(vis.win.selection.pos - to_stop, to_stop) == string.rep(' ', to_stop) then
|
|
|
|
vis:feedkeys(string.rep('<vis-delete-char-prev>', to_stop))
|
|
|
|
else
|
|
|
|
vis:feedkeys('<vis-delete-char-prev>')
|
|
|
|
end
|
2019-03-11 10:42:41 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";s", function()
|
2020-03-14 13:37:56 +01:00
|
|
|
vis:command("!sent '"..vis.win.file.path.."'")
|
2019-03-11 10:42:41 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ";p", function()
|
|
|
|
vis:command("<xclip -o")
|
|
|
|
end)
|
2019-06-04 21:40:57 +02:00
|
|
|
|
|
|
|
vis:map(vis.modes.VISUAL, ';a', function()
|
|
|
|
if vis.count then
|
|
|
|
vis:command(string.format(':|par %d', vis.count))
|
2019-12-07 00:07:11 +01:00
|
|
|
vis.count = nil
|
2019-06-04 21:40:57 +02:00
|
|
|
else
|
|
|
|
vis:command(':|par')
|
|
|
|
end
|
|
|
|
end)
|
2019-10-29 19:38:32 +01:00
|
|
|
|
|
|
|
vis:command_register("sts", function(argv, force, win, selection, range)
|
|
|
|
local lines = win.file.lines
|
|
|
|
for index=1, #lines do
|
|
|
|
lines[index] = lines[index]:gsub("%s+$", "")
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end, "Strip line trailing spaces")
|