vis: rework mappings
parent
572d07cd3e
commit
43f1666d76
|
@ -34,76 +34,25 @@ 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
|
||||
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, 'Close all unfocused windows')
|
||||
vis:map(m.NORMAL, ' w', function() vis:command('w') end)
|
||||
vis:map(m.NORMAL, ' q', function() vis:command('q') end)
|
||||
vis:map(m.NORMAL, ' Q', function() vis:command('q!') end)
|
||||
|
||||
vis:map(m.NORMAL, ' e', function()
|
||||
local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
|
||||
local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "Edit 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, 'pick file to :e')
|
||||
end, 'Edit file')
|
||||
|
||||
vis:map(m.NORMAL, ' o', function()
|
||||
local s, f = vis:pipe('find -type f | vis-menu -l 5 -p "pick file"')
|
||||
vis:map(m.NORMAL, ' cd', function()
|
||||
local s, f = vis:pipe('find -type d | vis-menu -l 5 -p "Change directory"')
|
||||
if s ~= 0 or not f then return end
|
||||
cmd = ('o "%s"'):format(f:sub(1, -2))
|
||||
cmd = ('cd "%s"'):format(f:sub(1, -2))
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
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 s, word = vis:pipe(
|
||||
vis.win.file or nil,
|
||||
vis.win.viewport.bytes,
|
||||
'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 = ('o "%s"'):format(file)
|
||||
vis:info(cmd)
|
||||
vis:command(cmd)
|
||||
vis.win.selection:to(tonumber(lineno), line:find(word))
|
||||
end, 'grep and pick file to :o')
|
||||
end, 'Change directory')
|
||||
|
||||
-- editor options
|
||||
vis.options.autoindent = true
|
||||
|
|
Loading…
Reference in New Issue