Current Behavior
I am building a plugin for fast, efficient normal mode commands over multiple lines. A representative function of what I am currently doing is the following:
User Interface
- It asks the user for a text object within which to perform the normal mode command
- It asks for a regex describing lines on which to perform a command
- It asks for the command to run
- It runs the command
Code
function! s:lines(...) abort
return [line("'["), line("']")]
endfunction
function! s:gObject(...) abort
if !a:0
let &operatorfunc = matchstr(expand('<sfile>'), '[^. ]*$')
return 'g@'
else
let [lnum1, lnum2] = <SID>lines(a:0, a:1)
let search = input("Run (Leave empty for last search): g/\\v")
let prompt = lnum1 . "," . lnum2 . "g/\\v" . search . "/". "norm "
let cmd = input("Run: " . a:prompt)
exec a:prompt . cmd
endif
endfunction
Desired Outcome
I now want to add repeatability. I want to be able to hit the . key and replay the entire sequence. This means it should perform the same motion to select a text object, perform the same search and run the same command as in the previous run.
I can accomplish this by recording a macro before I run the function, then replaying the macro will produce exactly the behavior that I want. I want that exact outcome, but without the user overhead of declaring a macro.
What I have tried
- Having vim-repeat installed and pressing
.. This reruns the text selection, but not the input commands (hence the question). - Recording a macro of the sequence and replaying it. This leads to poor UX.
Thanks in advance for your help.