Add more vim crazyness

This commit is contained in:
Francesco Abbate 2021-03-27 20:15:25 +01:00
parent 879018502f
commit fbefcc2b72
2 changed files with 19 additions and 8 deletions

View File

@ -66,7 +66,8 @@ function keymap.on_key_pressed(k)
local mode = core.get_editing_mode(core.active_view)
if mode then
local vim = require "core.vim"
return vim.on_key_pressed(mode, stroke, k)
local accepted = vim.on_key_pressed(mode, stroke, k)
if accepted then return true end
end
local commands = keymap.map[stroke]
if commands then

View File

@ -24,8 +24,8 @@ local function table_find(t, e)
end
end
local verbs_obj = {'d', 'c'}
local verbs_imm = {'y', 'p', 'h', 'j', 'k', 'l', 'x', 'i', 'u'}
local verbs_obj = {'c', 'd'}
local verbs_imm = {'a', 'h', 'i', 'j', 'k', 'l', 'p', 'u', 'x', 'y', 'left', 'right', 'up', 'down'}
local vim_objects = {'d', 'e', 'w', '$'}
local vim_object_map = {
@ -40,11 +40,18 @@ local function vim_execute(verb, mult, object)
command.perform_many(mult - 1, 'doc:move-to-next-line')
command.perform('doc:move-to-end-of-line')
else
if object == 'e' then
command.perform('doc:move-to-next-char')
end
command.perform_many(mult, 'doc:move-to-' .. vim_object_map[object])
if object == 'e' then
command.perform('doc:move-to-previous-char')
end
end
elseif verb == 'd' then
if object == '$' then
command.perform_many(mult, 'doc:select-to-next-line')
command.perform_many(mult - 1, 'doc:select-to-next-line')
command.perform('doc:select-to-end-of-line')
elseif object == 'd' then
command.perform('doc:move-to-start-of-line')
command.perform_many(mult, 'doc:select-to-next-line')
@ -58,16 +65,19 @@ local function vim_execute(verb, mult, object)
command.perform('doc:copy')
command.perform('doc:cut')
command.perform('core:set-insert-mode')
elseif verb == 'h' then
elseif verb == 'h' or verb == 'left' then
command.perform_many(mult, 'doc:move-to-previous-char')
elseif verb == 'j' then
elseif verb == 'j' or verb == 'down' then
command.perform_many(mult, 'doc:move-to-next-line')
elseif verb == 'k' then
elseif verb == 'k' or verb == 'up' then
command.perform_many(mult, 'doc:move-to-previous-line')
elseif verb == 'l' then
elseif verb == 'l' or verb == 'right' then
command.perform_many(mult, 'doc:move-to-next-char')
elseif verb == 'x' then
command.perform_many(mult, 'doc:delete')
elseif verb == 'a' then
command.perform('core:set-insert-mode')
command.perform('doc:move-to-next-char')
elseif verb == 'i' then
command.perform('core:set-insert-mode')
elseif verb == 'p' then