179

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
  • 6,087
  • 9
  • 44
  • 71
Jeff
  • 11,233
  • 10
  • 44
  • 85
  • 11
    http://www.viemu.com/vi-vim-cheat-sheet.gif – Sam Brinck Feb 22 '12 at 21:33
  • 9
    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

301

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

Lars Kotthoff
  • 101,128
  • 13
  • 187
  • 191
64

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
  • 109,816
  • 33
  • 208
  • 305
9

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

Mateusz Piotrowski
  • 6,087
  • 9
  • 44
  • 71
Alexander Corwin
  • 1,050
  • 6
  • 9
  • 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 – arkadyt 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
2

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

Philia Fan
  • 3,990
  • 1
  • 10
  • 6