From 948a4e046dc1af3a21758041eecf694a141139d7 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 24 Mar 2021 16:59:13 +0100 Subject: [PATCH] Fix behavior of e and w vim objects --- data/core/commands/doc.lua | 1 + data/core/doc/translate.lua | 14 +++++++++++++- data/core/keymap.lua | 8 ++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 768a4643..6e8a8b02 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -337,6 +337,7 @@ local translations = { ["next-char"] = translate.next_char, ["previous-word-start"] = translate.previous_word_start, ["next-word-end"] = translate.next_word_end, + ["next-word-begin"] = translate.next_word_begin, ["previous-block-start"] = translate.previous_block_start, ["next-block-end"] = translate.next_block_end, ["start-of-doc"] = translate.start_of_doc, diff --git a/data/core/doc/translate.lua b/data/core/doc/translate.lua index b084e89a..8973ede2 100644 --- a/data/core/doc/translate.lua +++ b/data/core/doc/translate.lua @@ -42,7 +42,7 @@ function translate.previous_word_start(doc, line, col) end -function translate.next_word_end(doc, line, col) +function translate.up_to_word(doc, line, col) local prev local end_line, end_col = translate.end_of_doc(doc, line, col) while line < end_line or col < end_col do @@ -53,10 +53,22 @@ function translate.next_word_end(doc, line, col) line, col = doc:position_offset(line, col, 1) prev = char end + return line, col +end + + +function translate.next_word_end(doc, line, col) + line, col = translate.up_to_word(doc, line, col) return translate.end_of_word(doc, line, col) end +function translate.next_word_begin(doc, line, col) + line, col = translate.end_of_word(doc, line, col) + return translate.up_to_word(doc, line, col) +end + + function translate.start_of_word(doc, line, col) while true do local line2, col2 = doc:position_offset(line, col, -1) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 6a03580c..1676b50e 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -29,10 +29,11 @@ end keymap.vim_verbs_obj = {'d', 'c'} keymap.vim_verbs_imm = {'y', 'p', 'h', 'j', 'k', 'l', 'x', 'i', 'u'} -keymap.vim_objects = {'w', '$'} +keymap.vim_objects = {'e', 'w', '$'} local vim_object_map = { - ['w'] = 'next-word-end', + ['e'] = 'next-word-end', + ['w'] = 'next-word-begin', ['$'] = 'end-of-line', } @@ -136,6 +137,9 @@ function keymap.on_key_pressed(k) keymap.vim_execute(keymap.command_verb, keymap.command_mult, stroke) keymap.reset_vim_command() return true + elseif stroke == 'escape' then + keymap.reset_vim_command() + return true end elseif mode == 'insert' then if stroke == 'escape' then