Editable dot register#19342
Conversation
|
The above bug has been fixed, but there are the following issues: Issue 1: Even when the completion plugin overwrites the . register, it seems to be restored somehow. The timing is unclear. Issue 2: The overwritten dot register value is not written to the buffer. Only the internal display changes. As a countermeasure, I'm manipulating the Redo buffer, but it doesn't seem to be taking effect. |
|
I have changed it to the draft. Because it does not work well. The help is welcome. |
| size_t len = str ? STRLEN(str) : 0; | ||
|
|
||
| vim_free(last_insert.string); | ||
| last_insert.string = alloc(len * MB_MAXBYTES + 5); |
There was a problem hiding this comment.
len is already the number of bytes in the string. You shouldn't multiply it with the number of bytes in a single character.
| last_insert.string = alloc(len * MB_MAXBYTES + 5); | |
| last_insert.string = alloc(len * 3 + 5); |
|
Dot repeat works by |
|
Probably this works well. https://gist.github.com/mattn/5989cc3cf2edf47a25fa977a9cabc8a9 |
It works dot register changes https://gist.github.com/mattn/5989cc3cf2edf47a25fa977a9cabc8a9
|
Usage: Thanks. I have included the patch. It works from command line. But one problem exists. If plugin changes dot register, dot register changes seems restored. |
Thank you for the information. I have not found them. |
|
I get it. /*
* Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff.
* Used after executing autocommands and user functions.
*/
void
restoreRedobuff(save_redo_T *save_redo)
{
free_buff(&redobuff);
redobuff = save_redo->sr_redobuff;
free_buff(&old_redobuff);
old_redobuff = save_redo->sr_old_redobuff;
}It restores dot register changes. |
|
I have added |
Fixed. |
You seem to be doing things haphazardly every time. |
|
The following comments were generated by AI (Claude Opus 4.5). Here are the specification concerns when making the 1. Ambiguity of Input FormatWhat should users set? let @. = "hello" " Text only?
let @. = "ihello" " Command character + text?
let @. = "ihello\<ESC>" " Command + text + ESC?The current patch tries to auto-detect the command character, but this is ambiguous. For example, what if you want to insert a word starting with let @. = "ice cream" " Is 'i' a command? Or text?2. Consistency with the
|
|
Currently, the CI is being fixed. I'm sorry, please wait. Since the specification was not finalized, I had postponed the documentation. I am currently documenting the current specification. We have finally reached the stage where the code is working, and there is still room for consideration regarding the specification. I didn't think of having AI review the pull request code. Thank you. |
|
I have updated the implementation and the documentation. |
|
I'm quite confused by this PR so I'm probably missing something very obvious as others seem happy with it. The Making this register writeable might be reasonable but I don't understand using it as an interface to the repeat command, at all. Why not offer a proper builtin function interface? Having the register perform double duty seems like a bad idea. |
|
Thank you for this thoughtful feedback and for pointing out these concerns. Context from Previous DiscussionsThis feature has been requested multiple times with specific use cases:
Your Valid ConcernsYou're correct that:
The Core ProblemVim's redo buffer uses a special internal format that's not accessible to scripts. This prevents:
Revised Proposal: Dictionary-Based FunctionsAfter considering your feedback, I believe we should use dedicated functions API Design" NEW: Repeat command control
call setrepeat({'cmd': 'dd'}) " Set repeat command
call setrepeat({'cmd': 'i', 'text': 'Hello'}) " Set insert operation
echo getrepeat()
" → {'cmd': 'dd'}
" → {'cmd': 'i', 'text': 'Hello'}
" EXISTING: Text-only access (unchanged)
echo getreg('.')
" → 'Hello' (last inserted text, unchanged behavior)Key Use Cases Enabled1. Save/Restore (telescope, neovim#33030) " Save before temporary edits
let saved = getrepeat()
" ... prompt buffer edits that would overwrite . ...
" Restore original repeat
call setrepeat(saved)2. Repeat History (#6299) " Save current repeat before making other changes
let important_repeat = getrepeat()
" ... make other edits ...
" Restore and use the saved repeat
call setrepeat(important_repeat)
normal! .3. Custom Plugin Integration (vim-repeat use case) function! MyComplexOperation()
" ... complex logic ...
" Make this operation repeatable with .
call setrepeat({'cmd': ':call MyComplexOperation()'})
endfunction4. Repeat History Management (#6346 goal) " Plugin can maintain history
let g:repeat_history = []
autocmd TextChanged * call add(g:repeat_history, getrepeat())
" Access previous repeats
call setrepeat(g:repeat_history[1])
normal! .Dictionary FieldsPhase 1 (implement now): {
'cmd': 'string' " Required - the command
'text': 'string' " Optional - text to insert (for insert mode)
}Phase 2 (future extensibility): {
'cmd': 'string'
'text': 'string'
'type': 'string' " 'normal', 'insert', 'visual'
'mode': 'string' " 'v', 'V', CTRL-V
'count': number " Repeat count
'register': 'string' " Target register
}BenefitsClean Separation:
Backward Compatibility:
Enables All Requested Use Cases:
Future-Proof:
Current Limitations (Acceptable for Phase 1)
Implementation PlanPhase 1 (this PR, if acceptable): setrepeat({dict})
Fields: 'cmd' (required), 'text' (optional)
getrepeat()
Returns: {dict} with same structure
" Existing behavior unchanged
getreg('.') → string (last inserted text)
" Comprehensive tests including save/restore scenarios
" Documentation with use case examplesPhase 2 (future): " Enhanced dictionary support for complex operations
setrepeat({'type': 'visual', 'mode': 'v', 'count': 3, 'cmd': 'd'})
" Backward compatibility maintainedQuestions
I'm willing to completely rework the PR to use this dictionary-based approach. |

neovim/neovim#33030
Current dot register is not editable.
https://github.com/tpope/vim-repeat plugin already exists. But when using this plugin, users must install
repeat.vimand there are side effects such as changing the mappings to custom ones. Therefore, I adopted an approach of modifying the core functionality to make the dot register changeable from scripts.Design Decisions
This PR makes the dot register writable, enabling customization of the repeat
command behavior without requiring external plugins like vim-repeat.
Command Interpretation (Finalized)
The dot register represents a command sequence, not just text. This is
consistent with how
:normalworks and the fundamental nature of the dotcommand (
.), which repeats the last change (an operation), not just text.Implementation:
[iaoOIAcsSC], it's treated as an insert mode command:normalbehavior - no implicit commands are addedExamples:
Note: The string is executed as-is, similar to
:normal. Users areresponsible for providing valid command sequences.