Add setrepeat() and getrepeat() functions to allow scripts to programmatically control the dot (.) repeat command.
This enables plugins to:
.This addresses several long-standing feature requests:
. command while making other changes, then restore it. repeat" Set repeat command call setrepeat({'cmd': 'dd'}) " Normal mode call setrepeat({'cmd': 'i', 'text': 'Hello'}) " Insert mode " Get repeat command echo getrepeat() " → {'cmd': 'dd', 'text': ''} " → {'cmd': 'i', 'text': 'Hello'} " Existing functionality unchanged echo getreg('.') " Still returns last inserted text (read-only)
Phase 1 (this PR):
{
'cmd': 'string' " Required - the command to repeat
'text': 'string' " Optional - text to insert (for insert mode)
}Future extensions (Phase 2):
{
'cmd': 'string'
'text': 'string'
'type': 'string' " 'normal', 'insert', 'visual'
'mode': 'string' " 'v', 'V', CTRL-V
'count': number " Repeat count
'register': 'string' " Target register
}function! PromptBufferOperation() " Save current repeat let saved = getrepeat() " Temporary edits in prompt buffer " (these would normally overwrite the repeat) " Restore original repeat call setrepeat(saved) endfunction
function! MyComplexCommand() " ... complex operation ... " Make it repeatable with . call setrepeat({'cmd': ':call MyComplexCommand()'}) endfunction command! MyCommand call MyComplexCommand() " User can now use . to repeat :MyCommand
let g:repeat_history = [] " Save current repeat call add(g:repeat_history, getrepeat()) " Later, restore from history call setrepeat(g:repeat_history[0]) normal! .
. register?This is a redesign of #19342 based on community feedback. The original approach had several issues:
getreg('.') behavior could break scriptsThe new approach:
getreg('.') unchanged (backward compatible)Documented in the help files:
Insert mode overwrites setrepeat()
When entering/leaving insert mode, Vim's automatic recording overwrites custom repeats.
Workaround: Call setrepeat() after insert mode operations.
setline() and similar not recorded
Text modification functions don't update the repeat command.
Workaround: Use feedkeys() to simulate typing.
Visual mode not supported
Will be added in Phase 2 with additional dictionary fields.
Limited info for user operations
getrepeat() provides full info only for setrepeat()-set values.
User operations return limited information.
These limitations don't affect the primary use cases (save/restore, plugin integration, history).
Potential enhancements:
type and mode fields)count field)register field)getrepeat() for user operationsAll can be added via dictionary fields without breaking changes.
Ready for review. This provides a solid foundation for script control of
the dot command while maintaining backward compatibility and allowing future
enhancements.
https://github.com/vim/vim/pull/19413
(8 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@Shougo pushed 2 commits.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@Shougo pushed 2 commits.
You are receiving this because you are subscribed to this thread.![]()