I think I'm almost there, maybe can use this as inspiration to make it work. I'm making use of kana/operator-user as in the suggested plugins.
The problem is entering insert mode during the repetition, so I've created a different operator to repeat using paste:
if exists('g:loaded_operator_insert')
finish
endif
let g:loaded_operator_insert = 1
let s:save_cpo = &cpo
set cpo&vim
call operator#user#define('insert-i', 'operator#insert#insert_i')
call operator#user#define('insert-a', 'operator#insert#insert_a')
call operator#user#define('insert-i-repeat', 'operator#insert#insert_i_repeat')
call operator#user#define('insert-a-repeat', 'operator#insert#insert_a_repeat')
let &cpo = s:save_cpo
unlet s:save_cpo
Which works like this:
let s:save_cpo = &cpo
set cpo&vim
" Public API {{{1
function! operator#insert#insert_i(motion_wise)
return s:operator_insert_i(a:motion_wise)
endfunction
function! operator#insert#insert_a(motion_wise)
return s:operator_insert_a(a:motion_wise)
endfunction
function! operator#insert#insert_i_repeat(motion_wise)
return s:operator_insert_i_repeat(a:motion_wise)
endfunction
function! operator#insert#insert_a_repeat(motion_wise)
return s:operator_insert_a_repeat(a:motion_wise)
endfunction
"}}}
" Private {{{1
function! s:operator_insert_i_repeat(motion_wise)
let s:original_pos = getpos("'[")[1:]
call cursor(s:original_pos)
normal! ".P
endfunction
function! s:operator_insert_a_repeat(motion_wise)
call cursor(getpos("']")[1:])
if col("']") >= col("$") - 1
normal! ".p
else
normal! l
normal! ".p
endif
endfunction
function! s:operator_insert_i(motion_wise)
let s:original_pos = getpos("'[")[1:]
call cursor(s:original_pos)
startinsert
silent! call repeat#set("\<Plug>(operator-insert-i-repeat)", -1)
endfunction
function! s:operator_insert_a(motion_wise)
call cursor(getpos("']")[1:])
if col("']") >= col("$") - 1
startinsert!
else
normal! l
startinsert
endif
silent! call repeat#set("\<Plug>(operator-insert-a-repeat)", -1)
endfunction
"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
Now it does work, but when we do the .
we need to reenter the first time the text object. It is not ideal, but something is something.
ciwTEXT<C-r>"
-- operator insert,ciw<C-r>"TEXT
-- operator append (though not repeatable). – Maxim Kim Oct 21 '19 at 10:28gaiq
(go append in quote), I find operators really powerful @D.BenKnoble – Blasco Oct 21 '19 at 11:55