218

How can I jump to the next character X in vim?

I frequently use, e.g., dt: or ct: to delete/change everything up until a colon (or some other character).

Is there any short key combo to simply move my cursor position to that character?

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Jeff
  • 12,147
  • 10
  • 51
  • 87
  • 11
    http://www.viemu.com/vi-vim-cheat-sheet.gif – Sam Brinck Feb 22 '12 at 21:33
  • 11
    If only the top 2 partial answers had been one - and additionally contained this information: the unmentioned`T` will jump to _after_ the first sought character to the left, and I can confirm that the `;` and `,` repeaters work with all of `f`/`F`/`t`/`T`. – underscore_d Dec 22 '15 at 19:20

4 Answers4

389

You can type f<character> to put the cursor on the next character and F<character> for the previous one.

Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
77

t and f work without a command as well, so to move to colon use f: and to move to right before colon use t:

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
  • 4
    Is there a way to move to right after the colon? – james Mar 16 '22 at 04:19
  • @james you can always move to the symbol after the colon using `fSYMBOL`, if you want to edit text after the colon you can use `f:a` – Ilay Jun 25 '23 at 16:57
10

If you do a search for that character with /, you can then hit n to move to the next occurrence of it.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Alexander Corwin
  • 1,097
  • 6
  • 11
  • I'm wondering how to undo this find once I've found the character. All matching characters seem to remain highlighted in the current buffer. – newswim Oct 23 '18 at 07:20
  • 1
    @newswim, :nohl – iamarkadyt Feb 14 '19 at 05:50
  • You can also just search for something else (e.g. a bunch of garbage that won't be matched) to change the highlighted search string. There is also `:set invhls` which is useful for toggling the highlights off and on (I map this to a shortcut for quick toggling). – FazJaxton Apr 04 '19 at 14:34
3

Maybe you are just searching for a pure vim combination but EasyMotion is a plugin that worth trying. HTH. :)

Philia Fan
  • 4,388
  • 1
  • 12
  • 6