.config/vis: update config, theme, use local vis-std.lua
parent
7aa7dd1750
commit
4bfd6003aa
|
@ -109,8 +109,10 @@ lex:embed(html, html_start_rule, html_end_rule)
|
|||
|
||||
-- Embedded YAML.
|
||||
local yaml = lexer.load('yaml')
|
||||
local yaml_start_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl
|
||||
local yaml_end_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl
|
||||
local doc_bounds_rule = yaml:get_rule('doc_bounds')
|
||||
local hr_rule = lex:get_rule('hr')
|
||||
local yaml_start_rule = doc_bounds_rule - hr_rule
|
||||
local yaml_end_rule = doc_bounds_rule - hr_rule
|
||||
lex:embed(yaml, yaml_start_rule, yaml_end_rule)
|
||||
|
||||
return lex
|
||||
|
|
|
@ -25,6 +25,7 @@ end)
|
|||
-- apply additional cursor styles on WIN_STATUS
|
||||
vis.events.subscribe(vis.events.WIN_STATUS, function(win)
|
||||
local pos = win.selection.pos
|
||||
if not pos then return end
|
||||
local style_id = win ~= vis.win and
|
||||
win['STYLE_CURSOR'] or
|
||||
win['STYLE_CURSOR_'..vis.mode] or
|
||||
|
|
|
@ -12,10 +12,15 @@ local mode_strings = {
|
|||
|
||||
local e = vis.events
|
||||
|
||||
-- editor options
|
||||
-- init
|
||||
e.subscribe(e.INIT, function()
|
||||
require("themes.basic")
|
||||
-- load theme
|
||||
require("themes/basic")
|
||||
local lexers = vis.lexers
|
||||
lexers.lexers = {}
|
||||
if lexers.load and not lexers.property then lexers.load("text") end
|
||||
|
||||
-- mappings
|
||||
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>')
|
||||
|
@ -29,6 +34,11 @@ e.subscribe(e.INIT, function()
|
|||
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, 'gA', '<vis-motion-screenline-end><vis-motion-char-prev><vis-append-char-next>')
|
||||
|
||||
vis:map(m.NORMAL, '<C-h>', '<vis-jumplist-prev>');
|
||||
vis:map(m.NORMAL, '<C-l>', '<vis-jumplist-next>');
|
||||
|
||||
vis:map(m.NORMAL, '<C-w>o', function()
|
||||
local unclosed
|
||||
for win in vis:windows() do
|
||||
|
@ -41,46 +51,65 @@ e.subscribe(e.INIT, function()
|
|||
vis.win = unclosed
|
||||
vis:info('No write since last change')
|
||||
end
|
||||
end)
|
||||
end, 'Close all unfocused windows')
|
||||
|
||||
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
|
||||
local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
|
||||
if s ~= 0 or not f then return end
|
||||
cmd = ('e "%s"'):format(f:sub(1, -2))
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
end)
|
||||
end, 'pick file to :e')
|
||||
|
||||
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))
|
||||
local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
|
||||
if s ~= 0 or not f then return end
|
||||
cmd = ('o "%s"'):format(f:sub(1, -2))
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
end)
|
||||
end, 'pick file to :o')
|
||||
|
||||
vis:map(m.NORMAL, ' b', function()
|
||||
local wins = {}
|
||||
local i, wi = 0, 0
|
||||
for win in vis:windows() do
|
||||
table.insert(wins, ('%q:%q'):format(i,win.file.name or '[No_Name]'))
|
||||
if win == vis.win then wi = i end
|
||||
i = i + 1
|
||||
end
|
||||
wins = table.concat(wins, '\n')
|
||||
local s, w = vis:pipe(('printf "%s" | vis-menu -l 5 -p "pick window"'):format(wins))
|
||||
if s ~= 0 or not w then return end
|
||||
local si = tonumber(w:match('^(%d+):.*$') or wi)
|
||||
if si == wi then return end
|
||||
local action = si > wi and '<vis-window-next>' or '<vis-window-prev>'
|
||||
for i=1,math.abs(si-wi) do
|
||||
vis:feedkeys(action)
|
||||
end
|
||||
end, 'pick window to move to')
|
||||
|
||||
vis:map(m.NORMAL, ' g', function()
|
||||
local _, w = vis:pipe(
|
||||
local s, word = 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
|
||||
'grep -Eo "\\w\\w\\w+" | sort -u | vis-menu -l 5 -p "grep"')
|
||||
if s ~= 0 or not word then return end
|
||||
word = word:sub(1, -2)
|
||||
local s, f = vis:pipe(('grep -n "%s" ** | tr "\\t" " " | vis-menu -l 5 -p ":o"'):format(word))
|
||||
if s ~= 0 or not f then return end
|
||||
local file, lineno, line = f:match("^(.+):(%d+):(.*)$")
|
||||
if file == nil then return end -- TODO report error
|
||||
cmd = ('vsplit "%s"'):format(file)
|
||||
cmd = ('o "%s"'):format(file)
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
vis.win.selection:to(tonumber(lineno), line:find(w))
|
||||
end)
|
||||
vis.win.selection:to(tonumber(lineno), line:find(word))
|
||||
end, 'grep and pick file to :o')
|
||||
|
||||
-- editor options
|
||||
vis.options.autoindent = true
|
||||
end)
|
||||
|
||||
-- window options
|
||||
|
||||
-- window open
|
||||
e.subscribe(e.WIN_OPEN, function(win)
|
||||
win.options.colorcolumn = 81
|
||||
win.options.relativenumbers = true
|
||||
|
@ -99,8 +128,7 @@ e.subscribe(e.WIN_OPEN, function(win)
|
|||
end)
|
||||
|
||||
-- statusline
|
||||
|
||||
function set_statusline(win, mode_string)
|
||||
e.subscribe(e.WIN_STATUS, function(win)
|
||||
local left_parts = {}
|
||||
local right_parts = {}
|
||||
local file = win.file
|
||||
|
@ -110,7 +138,7 @@ function set_statusline(win, mode_string)
|
|||
|
||||
if vis.win == win then
|
||||
-- mode
|
||||
table.insert(left_parts, mode_string)
|
||||
table.insert(left_parts, mode_strings[vis.mode])
|
||||
|
||||
-- selection
|
||||
table.insert(left_parts, selection.number..'/'..#win.selections)
|
||||
|
@ -137,18 +165,13 @@ function set_statusline(win, mode_string)
|
|||
table.insert(right_parts, selection.col)
|
||||
|
||||
-- fillchars
|
||||
local left = table.concat(left_parts, " ")
|
||||
local right = table.concat(right_parts, " ")
|
||||
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)
|
||||
os.execute('printf "\\e];vis: '..title..(modified and '[+]' or '')..'\\e"')
|
||||
|
|
Loading…
Reference in New Issue