.config/vis: update config, theme
parent
ef7c19aff9
commit
3fe596568f
|
@ -25,13 +25,11 @@ end)
|
|||
-- apply additional cursor styles on WIN_STATUS
|
||||
vis.events.subscribe(vis.events.WIN_STATUS, function(win)
|
||||
local pos = win.selection.pos
|
||||
win:style(win['STYLE_CURSOR'], pos, pos)
|
||||
if win == vis.win then
|
||||
local mode_style_id =
|
||||
win['STYLE_CURSOR_'..vis.mode] or
|
||||
win['STYLE_CURSOR_PRIMARY']
|
||||
win:style(mode_style_id, pos, pos)
|
||||
end
|
||||
local style_id = win ~= vis.win and
|
||||
win['STYLE_CURSOR'] or
|
||||
win['STYLE_CURSOR_'..vis.mode] or
|
||||
win['STYLE_CURSOR_PRIMARY']
|
||||
win:style(style_id, pos, pos)
|
||||
end)
|
||||
|
||||
local lexers = vis.lexers
|
||||
|
|
|
@ -1,51 +1,104 @@
|
|||
require('vis')
|
||||
|
||||
local m = vis.modes
|
||||
local mode_strings = {
|
||||
[vis.modes.NORMAL] = 'NORMAL',
|
||||
[vis.modes.OPERATOR_PENDING] = 'OPERATOR-PENDING',
|
||||
[vis.modes.VISUAL] = 'VISUAL',
|
||||
[vis.modes.VISUAL_LINE] = 'VISUAL-LINE',
|
||||
[vis.modes.INSERT] = 'INSERT',
|
||||
[vis.modes.REPLACE] = 'REPLACE',
|
||||
[m.NORMAL] = 'NORMAL',
|
||||
[m.OPERATOR_PENDING] = 'OPERATOR-PENDING',
|
||||
[m.VISUAL] = 'VISUAL',
|
||||
[m.VISUAL_LINE] = 'VISUAL-LINE',
|
||||
[m.INSERT] = 'INSERT',
|
||||
[m.REPLACE] = 'REPLACE',
|
||||
}
|
||||
|
||||
-- editor options
|
||||
vis.events.subscribe(vis.events.INIT, function()
|
||||
vis.options.theme = require("themes.basic")
|
||||
local e = vis.events
|
||||
|
||||
vis:map(vis.modes.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(vis.modes.VISUAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(vis.modes.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(vis.modes.VISUAL, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(vis.modes.VISUAL_LINE, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(vis.modes.VISUAL_LINE, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(vis.modes.NORMAL, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(vis.modes.VISUAL, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(vis.modes.VISUAL_LINE, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(vis.modes.NORMAL, 'P', '<vis-register>+<vis-put-before>')
|
||||
vis:map(vis.modes.VISUAL, 'P', '<vis-register>+<vis-put-before>')
|
||||
vis:map(vis.modes.VISUAL_LINE, 'P', '<vis-register>+<vis-put-before>')
|
||||
-- editor options
|
||||
e.subscribe(e.INIT, function()
|
||||
require("themes.basic")
|
||||
|
||||
vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(m.VISUAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(m.NORMAL, 'y', '<vis-register>+<vis-operator-yank>')
|
||||
vis:map(m.VISUAL, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(m.VISUAL_LINE, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(m.VISUAL_LINE, 'd', '<vis-register>+<vis-operator-delete>')
|
||||
vis:map(m.NORMAL, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(m.VISUAL, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(m.VISUAL_LINE, 'p', '<vis-register>+<vis-put-after>')
|
||||
vis:map(m.NORMAL, 'P', '<vis-register>+<vis-put-before>')
|
||||
vis:map(m.VISUAL, 'P', '<vis-register>+<vis-put-before>')
|
||||
vis:map(m.VISUAL_LINE, 'P', '<vis-register>+<vis-put-before>')
|
||||
|
||||
vis:map(m.NORMAL, '<C-w>o', function()
|
||||
local unclosed
|
||||
for win in vis:windows() do
|
||||
if win == vis.win then goto continue end
|
||||
if win:close() then goto continue end
|
||||
unclosed = win
|
||||
::continue::
|
||||
end
|
||||
if unclosed then
|
||||
vis.win = unclosed
|
||||
vis:info('No write since last change')
|
||||
end
|
||||
end)
|
||||
|
||||
vis:map(m.NORMAL, ' e', function()
|
||||
local _, f = vis:pipe('find -type f | vis-menu -l 5 -p ":e"')
|
||||
if f == nil then return end
|
||||
cmd = ('e "%s"'):format(f:sub(1, -2))
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
end)
|
||||
|
||||
vis:map(m.NORMAL, ' o', function()
|
||||
local _, f = vis:pipe('find -type f | vis-menu -l 5 -p ":o"')
|
||||
if file == nil then return end
|
||||
cmd = ('vsplit "%s"'):format(f:sub(1, -2))
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
end)
|
||||
|
||||
vis:map(m.NORMAL, ' g', function()
|
||||
local _, w = vis:pipe(
|
||||
vis.win.file or nil,
|
||||
vis.win.viewport.bytes,
|
||||
'grep -Eo "\\w\\w\\w+" | sort | uniq | vis-menu -l 5 -p "grep"')
|
||||
if w == nil then return end
|
||||
w = w:sub(1, -2)
|
||||
local _, f = vis:pipe(('grep -n "%s" ** | tr "\\t" " " | vis-menu -l 5 -p ":o"'):format(w))
|
||||
if f == nil then return end
|
||||
local file, lineno, line = f:match("^(.+):(%d+):(.*)$")
|
||||
if file == nil then return end -- TODO report error
|
||||
cmd = ('vsplit "%s"'):format(file)
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
vis.win.selection:to(tonumber(lineno), line:find(w))
|
||||
end)
|
||||
|
||||
vis.options.autoindent = true
|
||||
vis.options.ignorecase = true
|
||||
end)
|
||||
|
||||
-- window options
|
||||
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
||||
|
||||
e.subscribe(e.WIN_OPEN, function(win)
|
||||
win.options.colorcolumn = 81
|
||||
win.options.relativenumbers = true
|
||||
|
||||
if win.syntax == 'markdown' then
|
||||
win.options.breakat = " .])}_"
|
||||
win.options.breakat = " ])}_"
|
||||
win.options.expandtab = true
|
||||
win.options.tabwidth = 2
|
||||
win.options.wrapcolumn = 81
|
||||
end
|
||||
|
||||
if win.syntax == 'css' then
|
||||
win.options.expandtab = true
|
||||
win.options.tabwidth = 2
|
||||
end
|
||||
end)
|
||||
|
||||
vis.events.subscribe(vis.events.WIN_STATUS, function(win)
|
||||
set_statusline(win, mode_strings[vis.mode])
|
||||
end)
|
||||
-- statusline
|
||||
|
||||
function set_statusline(win, mode_string)
|
||||
local left_parts = {}
|
||||
|
@ -83,5 +136,36 @@ function set_statusline(win, mode_string)
|
|||
table.insert(right_parts, #file.lines..'/'..selection.line)
|
||||
table.insert(right_parts, selection.col)
|
||||
|
||||
win:status(table.concat(left_parts, " "), table.concat(right_parts, " "));
|
||||
-- fillchars
|
||||
local left = table.concat(left_parts, " ")
|
||||
local right = table.concat(right_parts, " ")
|
||||
|
||||
win:status(table.concat({ left, ('^'):rep(win.width - #left - #right - 2)}, ' '), right)
|
||||
end
|
||||
|
||||
e.subscribe(e.WIN_STATUS, function(win)
|
||||
set_statusline(win, mode_strings[vis.mode])
|
||||
end)
|
||||
|
||||
-- title
|
||||
|
||||
local modified = false
|
||||
local function set_title(title)
|
||||
vis:command('!printf "\\e];vis: '..title..(modified and '[+]' or '')..'\\e"')
|
||||
end
|
||||
|
||||
e.subscribe(e.WIN_OPEN, function(win)
|
||||
set_title(win.file.name or "[No Name]")
|
||||
end)
|
||||
|
||||
e.subscribe(e.FILE_SAVE_POST, function(file)
|
||||
modified = false
|
||||
set_title(file.name)
|
||||
end)
|
||||
|
||||
e.subscribe(e.WIN_STATUS, function(win)
|
||||
if not modified and win.file.modified then
|
||||
modified = true
|
||||
set_title(win.file.name)
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue