$30 off During Our Annual Pro Sale. View Details »

Designing Repeatable Edits: The Architecture o...

Designing Repeatable Edits: The Architecture of . in Vim

VimConf 2025 Small
https://vimconf.org/2025

Avatar for Satoru Kitaguchi

Satoru Kitaguchi

November 02, 2025
Tweet

More Decks by Satoru Kitaguchi

Other Decks in Programming

Transcript

  1. © 2025 Third Intelligence Satoru Kitaguchi Software Engineer at Third

    Intelligence About Me ^?:github|x)\.com/satorunooshie/?$ 2
  2. © 2025 Third Intelligence Beyond human, beyond AI — towards

    a new form of intelligence. Not the human brain, nor conventional AI. Third Intelligence is an AI research and development company committed to creating a new form of intelligence and AGI. Beyond raw intellect, we aim to build AI that thinks, converses, acts, and grows like a human — paving the way for a future where AI enhances the lives of people everywhere. We welcome those eager to join us in the challenge of creating and utilizing a new kind of intelligence that does not yet exist in the world, all within a globally competitive R&D environment. To learn more, please contact us below. 3
  3. © 2025 Third Intelligence 4 1. Intro: Why Dot matters

    2. Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy Agenda
  4. © 2025 Third Intelligence Can you explain what can —

    and canʼt — be dot-repeated? 💭 5
  5. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 6 Agenda
  6. © 2025 Third Intelligence The Source of Vim's Speed is

    Repetition. The dot command (.) is the ultimate Unit of Change for repetition. Philosophy: Optimize one action, and you optimize all future repetitions. Complex tasks can be broken down into "Movement" and ". Repeat". 👉 Fewer Keystrokes and Focused Thinking 7 Why dot matters?
  7. © 2025 Third Intelligence 8 ✔ Understand how Dot repeat

    works internally ✔ Learn to design “Dot-friendlyˮ edits ✔ Extend Dot to plugins with repeat.vim ✔ Rethink editing as design, not memory Goal of the Day
  8. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 9 Agenda
  9. © 2025 Third Intelligence Dot does not replay keystrokes. It

    re-applies the last change. The change repeated by . is the entire sequence of actions that begins and ends in Normal mode, and modifies the buffer. 10 Dot repeat = Replay last change
  10. © 2025 Third Intelligence replay keystrokes 11 Macro ≠ Dot,

    but Dot ≒ Micro Macro qaxciwfoo<Esc>q @a ciwfoo<Esc> . reapply last change Mechanism Key Inputs Edit Chunks Flexibility Undo Integration High Depends on Vimʼs edit model Hard Easy Basis
  11. © 2025 Third Intelligence 12 Repeatable / Non-Repeatable Actions Dot

    relies on Vimʼs “structured editsˮ. Visual or ad-hoc actions often donʼt produce repeatable change records. ✅ Repeatable ❌ Non-repeatable Operator + motion (daw, gUap) ⚠ Visual mode changes (vaw → c) Text objects (ci", da() feedkeys() based operations normal! commands Actions that split undo chunks Ex commands + repeat#set() registration Function calls without repeat registration
  12. © 2025 Third Intelligence normal! is repeatable - they are

    internally recorded just like operator + motion Ex is not repeatable by default - but can be repeatable via repeat#set() registration 13 normal! and ex commands normal! gUiw call MyAction() call repeat#set(":call MyAction()<CR>") ✅ Repeatable ❌ Non-repeatable ✅ Repeatable
  13. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 14 Agenda
  14. © 2025 Third Intelligence Visual mode often breaks dot repeat.

    Text objects donʼt. vaw cfoo<Esc> . ❌ Non-repeatable ciwfoo<Esc> . ✅ Repeatable 15 Visual vs Text Object Visual mode edits are not recorded structurally Text objects create repeatable, clean change records Records a mechanical character count change. Repeat fails to target the next word.
  15. © 2025 Third Intelligence 16 Simulates key input = not

    dot-repeatable Use normal!, not feedkeys() function! UpperCaseWord() call feedkeys("gUiw") endfunction ❌ feedkeys() function! UpperCaseWord() normal! gUiw endfunction ✅ normal! Executes internal command = dot-repeatable
  16. © 2025 Third Intelligence 17 When you use cursor keys

    (arrow keys) in Insert mode: • A new change chunk (undo unit) is created. • Vim treats the action as if you returned to Normal mode and then executed a cursor movement command. Do not use cursor keys <Up> <Down> <Left> <Right> ❌ Non-repeatable h, j, k, l, w, b… ✅ Repeatable
  17. © 2025 Third Intelligence dw . → Granularity for Resilience

    - Minimal Undo Chunks: Execute deletions as dw (single word) for minimal units - Safer Reversal: Provides granular control for easy, safe error correction. - Robust Workflow: Allows for mid-edit flexibility against changing decisions. 18 Keep undo chunks small 2dw d2w ❌ Non-repeatable dw. ✅ Repeatable Delete more than one word Delete more than one word
  18. © 2025 Third Intelligence Search (/) + Dot (.) :

    Minimal Chunks, Maximum Safety - Replacement as atomic changes ⟶ Small Undo Chunks. - Control: Easy reversal + Visual Confirmation. - Robustness: Prevents errors; resilient workflow. 19 Substitute (:s) vs. Search (/) + Dot (.) :%s/hoge/fuga/g ❌ Non-repeatable /hoge ciwfuga<Esc> n.n.n. ✅ Repeatable
  19. © 2025 Third Intelligence 20 undojoin merges the following edit

    into the same undo block. However, this does not extend dot repeat to replay the combined action. undojoin is only for undo chunk. Combine multiple edits normal! ciwfoo undojoin | normal! p
  20. © 2025 Third Intelligence ✔ Use text objects instead of

    Visual edits ✔ Use normal! instead of feedkeys() ✔ Use h,j,k,l instead of <Left>, <Right>, <Up>, <Down> ✔ Keep small undo chunk ✔ Think in terms of replayable structure, not ad-hoc actions 21 Best Practices for Dot Repeat
  21. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 22 Agenda
  22. © 2025 Third Intelligence g@ + operatorfunc → custom operator

    operatorfunc natuarally supports dot repeat 24 Custom operators = Dot-friendly building blocks function! s:ReplaceWithFoo(type) normal! `[v`]_d normal! Ifoo endfunction set operatorfunc=<SID>ReplaceWithFoo nnoremap <leader>rw :set opfunc=<SID>ReplaceWithFoo<CR>g@
  23. © 2025 Third Intelligence Visual + Ex → not structurally

    recorded → not . repeatable operatorfunc → operator-integrated edits → . repeatable & motion-composable function! s:Comment(type) “ handle type execute a:firstline . ',' . a:lastline . 'normal! I//' endfunction nnoremap <silent> gc :set opfunc=<SID>Comment<CR>g@ nnoremap <leader>d V:s/^/\/\/ /<CR> Refactor mappings to align with Dot 25 ❌ Visual + Ex ✅ operatorfunc
  24. © 2025 Third Intelligence ✔ Integrate custom operators with operatorfunc

    ✔ Rewrite mappings to be Dot-repeatable 🧠 Build your own “editing languageˮ centered around Dot repeat 26 Summary of “Rebuilding Your Editing Systemˮ
  25. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 27 Agenda
  26. © 2025 Third Intelligence • Plugins often break the undo

    structure • They rely on feedkeys() or Ex commands that bypass normal-mode edits • They are not integrated with Vimʼs internal repeat system → They act outside Vimʼs editing model Dot repeat only works for changes that Vim recognizes as “an editˮ. 28 Why doesnʼt Dot work with my plugin?
  27. © 2025 Third Intelligence 29 repeat.vim: The missing API for

    Dot repeat.vim — a widely used bridge between plugins and Vimʼs repeat system Written and maintained by Tim Pope (tpope) Provides an API (repeat#set({command}, v:count)) that lets plugins register repeatable actions Used by major plugins: surround.vim, speeddating.vim, unimpaired.vim, vim-easyclip, vim-radical… → In practice, repeat.vim is the de-facto standard infrastructure for dot-repeat support in plugins
  28. © 2025 Third Intelligence 30 Making a custom command repeatable

    function! AddSemicolon() if getline('.')[col('$') - 2] !=# ';' normal! A; endif call repeat#set(':call AddSemicolon()<CR>') endfunction nnoremap <leader>; :call AddSemicolon()<CR> repeat.vim isn’t just for plugins. any function or mapping can join Vim’s repeat system by calling repeat#set().
  29. © 2025 Third Intelligence ✅ Always keep undo block meaningful

    and small ⚠ Avoid splitting actions into multiple undo blocks 🔁 Dot only replays the last undo block 💥 If your mapping or plugin breaks undo, then Dot breaks too Whether itʼs a plugin or your own mapping, the principle stays the same. One undo block, one repeatable edit. 31 Undo block design = repeatability
  30. © 2025 Third Intelligence 1. Intro: Why Dot matters 2.

    Inside Dot: How repeat works 3. Writing Dot-Friendly Edits 4. Rebuilding Your Editing System 5. Plugins and repeat.vim 6. Advanced Techniques & Philosophy 32 Agenda
  31. © 2025 Third Intelligence 33 Use :normal . for scripting

    Combine with :global for batch edits Batch replay via :global :g/{pattern}/normal .
  32. © 2025 Third Intelligence 34 Key ideas • Turns the

    last change into a motion-aware operator • Use it like g.iw, g.ap, or g.} — “apply Dot thereˮ • Works best with clean, motion-based edits • Keeps cursor stable and undo history consistent g. = “Do the last change over this motion.ˮ Think of Dot as an operator you can aim anywhere. Applying Dot as an Operator function! RepeatOnMotion(type) " Save cursor position normal! m` " Select the operated range normal! `[v`] " Replay last change quietly silent! normal . " Return to cursor normal! `` endfunction set opfunc=<SID>RepeatOnMotion nnoremap g. g@
  33. © 2025 Third Intelligence 35 Align your hands with Dot.

    Donʼt memorize patterns. Design them. 🔁 Build habits around Dot 💭 Think in repeatable actions
  34. © 2025 Third Intelligence 1. Dot repeat is Vimʼs editing

    model 2. Design your edits to align with Dot 3. repeat.vim extends that model to plugins 4. Think in terms of reusable, structured actions 5. Editing is not memory — itʼs composition Key Takeaways 36
  35. 39