0

I'm trying to figure out a way to make a repeatable operator insert. To do so I'm trying to make use of tpope/repeat. My idea is to set a repeatable call that repeats the last operation, repeating the last operation as it is doesn't work as insert is executed in place.


let g:last_insert_operator_textobj = ''
function s:repeat_insert()
    " TODO: detect that last action was the insert operator.
    " gi := (go insert) operator (which is working)
    call feedkeys("gi".g:last_insert_operator_textobj)
endfunction
command! repeat_insert call s:repeat_insert()
nmap (operator-insert-i-repeat) <plug>repeat_insert

function s:check_if_repeat_insert()
    " TODO: detect that this insert is associated to the
    " (operator-insert) and not a normal insert

    let g:last_insert_operator_textobj = somehow_get_last_used_textobject_keys()

    autocmd! InsertLeave * "call repeat#set("\<Plug>(operator-insert-i-repeat)", -1)
endfunction

command! check_if_repeat_insert call s:check_if_repeat_insert()
autocmd! InsertLeave * call check_if_repeat_insert

If I could figure out how to retrieve the keys of the last used text object let g:last_insert_operator_textobj = somehow_get_last_used_textobject_keys() then the rest of the script I think it would work. Figuring out the " TODO: detect that this insert is associated to the (operator-insert) and not a normal insert shouldn't be too complicated.

10
  • 1
    I don't think this is possible Commented Oct 22, 2019 at 6:46
  • @ChristianBrabandt but how does vim know what text object was used when you use the . command? It must know somehow, right?
    – Blasco
    Commented Oct 22, 2019 at 6:48
  • 1
    Because Vim does keep track of the changes internally in the C source. That is nothing you can get access from VimScript. Commented Oct 22, 2019 at 8:11
  • What if instead you took the original from the other answer and added a onetime InsertLeave autocmd to do the repeat set before triggering the insert?
    – D. Ben Knoble
    Commented Oct 22, 2019 at 10:28
  • @ChristianBrabandt I see, makes sense, thank you for the guidance
    – Blasco
    Commented Oct 22, 2019 at 10:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.