Fix behavior of e and w vim objects

This commit is contained in:
Francesco Abbate 2021-03-24 16:59:13 +01:00
parent 3f4856bccd
commit 948a4e046d
3 changed files with 20 additions and 3 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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