215

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?

2
  • 11
    viemu.com/vi-vim-cheat-sheet.gif
    – Sam Brinck
    Feb 22, 2012 at 21:33
  • 11
    If only the top 2 partial answers had been one - and additionally contained this information: the unmentionedT 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. Dec 22, 2015 at 19:20

4 Answers 4

379

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

6
  • 136
    You can also use ; to repeat the operation and use , to repeat it in opposite direction.
    – Rsh
    Jun 15, 2014 at 5:46
  • 15
    This only seems to work with matches on the same line for me. Mar 25, 2016 at 17:30
  • 14
    @JpajiRajnish Yes. Use /<character> to match it anywhere. Mar 25, 2016 at 18:18
  • 1
    It seems that using f<character> (along with the ; and , characters for repeating the command) only works on the line the cursor is at. Is there a way to make it work across the entire file?
    – Aluthren
    Mar 25, 2020 at 22:56
  • 1
    @Rsh You saved my life with ,, sometimes I get overzealous and jump past and never knew I could go back.
    – Adam
    Dec 4, 2020 at 15:45
76

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:

1
  • 2
    Is there a way to move to right after the colon?
    – james
    Mar 16, 2022 at 4:19
10

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

3
  • 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, 2018 at 7:20
  • 1
    @newswim, :nohl
    – iamarkadyt
    Feb 14, 2019 at 5: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 4, 2019 at 14:34
4

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.