vimtricks.wiki Concise Vim tricks, one at a time.

How do I repeat the last f, t, F, or T character search on a line?

Answer

; / ,

Explanation

After using f, t, F, or T to jump to a character on the current line, pressing ; repeats the same search in the same direction, and , repeats it in the opposite direction. This turns single-character searches into a rapid-fire navigation system — jump to the first match, then tap ; to hop to each subsequent one.

How it works

  • f{char} moves the cursor forward to the next occurrence of {char} on the current line
  • t{char} moves forward to just before the next {char}
  • F{char} and T{char} do the same but search backward
  • ; repeats the last f/t/F/T motion in the original direction
  • , repeats it in the reverse direction
  • Both ; and , stay on the current line — they never wrap to other lines

Example

Given the text with the cursor at the beginning:

foo, bar, baz, qux, quux

Press f, to jump to the first comma. Now:

  • Press ; to jump to the second comma
  • Press ; again to jump to the third comma
  • Press , to jump back to the second comma

This works identically with t: press t, to land just before the first comma, then ; to land just before the second, and so on.

Tips

  • Pair ; with the dot command for blazing-fast edits: f,x deletes a comma, then ;. finds the next comma and deletes it too — repeat ;. as many times as needed
  • The ; and , keys remember whether you used f or t, forward or backward — so after Fa, pressing ; searches backward for the next a and , searches forward
  • Use df; (delete-find-semicolon) to delete up to and including a character, then ; to find the next one and . to delete to it as well
  • In operator-pending mode, f/t combined with ; can extend the reach: d2f, deletes through the second comma, but df, then d; achieves a similar result in two repeatable steps
  • If you remap ; and , to something else, you lose this repeat functionality — consider this before reassigning these keys
  • Some users map ; to : for faster command-line access — if you do this, remap the repeat-find to another key so you don't lose it
  • The f/t repeat state is global — using f or t for a new character replaces the previous one, so ; always repeats the most recent character search

Next

How do I edit multiple lines at once using multiple cursors in Vim?