25

Vimmers know that . can repeat simple changes. I tried to build a list of what can be repeated or not, but is there a list?

I tried to list what I know to be repeatable: they are all normal-mode commands:

  • Text insertion : a, A, i, I, o, O
  • Text changes involving registers: c, C, d, D, p, gp, P, gP, s, S,x, X
  • Other text changes: J, gJ, r, gr, R, gR, gU, gu, gw, gq, g?, ~, g~, <, >, =
  • Equivalent of these operations in visual mode.
  • Control-operations: C-A, C-X
  • gi will repeat the insertion but at current cursor position, not at last insert position. So it sort of works.

But it does not include:

  • All move and display commands (too numerous to be listed here)
  • All fold commands (z-commands, also numerous)
  • Mark (m)
  • Substitution repeat (&, g&)
  • Colon or Filter command (!, :, Q)
  • Macro recordings or playing (q or @, will repeat last repeatable action done while recording or playing ).
  • Diff put and get (dp, do)
  • Undo (u, U, C-R)
  • Yanks (y)

I know that tpope's repeat plugin can have custom plugins subscribe to the repetition mechanism. But by default, is the above list good?

Benoit
  • 76,634
  • 23
  • 210
  • 236
  • 1
    I would venture to say it probably repeats anything that `undo` would undo. I can't think of anything off the top of my head that conflicts with that statement (but I haven't used vim in a while now so things are becoming fuzzy). Maybe it's easier to find a list of things `undo` will undo than it is to find a list of things `.` will repeat. – Randy Morris Sep 24 '12 at 13:52
  • @RandyMorris "undo" could undo cmd line (e.g. :s/foo/bar/) changes, but "." cannot repeat them. – Kent Sep 24 '12 at 13:54
  • AFAK, "c, C, ..." can be repeated using "." – Andrea Pavoni Sep 24 '12 at 13:56
  • 1
    Ctrl-A ctrl-X to do the number changes can be "dot"-repeated as well. – Kent Sep 25 '12 at 08:28

4 Answers4

4

I believe a change is any command that modifies the current buffer. The . command excludes Ex commands (because that's a different mode that was bolted onto vi in the far history, I guess), and can optionally include yanks.

So for your list, :help change.txt, filtered for Ex commands, is probably the best source.

Note that when a change command cannot be applied (i.e. it beeps), it is also not registered for repeat; the command execution must be successful.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 1
    I have the _feeling_ that your answer is accurate, intuitively, however it is not because `.` does not repeat `&` nor `g&`. – Benoit Sep 25 '12 at 07:20
  • 1
    `&` and `g&` themselves repeat a command (last `:s`), so I guess that's the reason to exclude them. – rburny Aug 19 '15 at 09:11
2

some combination with v/V can be "dot" repeated too.

e.g.

Vgq, v/VU or v/Vu

Kent
  • 189,393
  • 32
  • 233
  • 301
1

Tim Pope's repeat.vim can make repeat many more things (including stuff like surround.vim and other must haves).

To repeat a motion, look at , / ; (forward/reverse direction).

To repeat an Ex command, @: is a good key combination

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I know about repeat.vim (it is mentioned in the question). Yes, `;,` can repeat `fFtT` motions. Maybe also mention `nN`. – Benoit Sep 26 '12 at 20:32
  • @Benoit Oh. I completely overlooked the mention. I think I used `/repeat` to scan for mentions on the whole page... Sorry about that – sehe Sep 26 '12 at 20:40
1

Insert mode expression register is NOT re-evaluated

Example: If you want to sort following inline lists of numbers,

 first 3,2,17,198,232,1,999 and some other text
 second 1,2,3,71,98,4,5 and some more text

consider these two ways using the expression register:

  1. ciW and then <C-r>=join(sort([<C-r>"]), ',')<CR>
  2. ciW and then <C-r>=join(sort(split(expand(@"), ',')), ',')<CR>

If you try to repeat either of them for the second line with ., vim simply enters again the same list from the first line. This might be expected by others but I was hoping that for the second way the expression register would be re-evaluated.

Hotschke
  • 9,402
  • 6
  • 46
  • 53