230

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
    Commented Feb 22, 2012 at 21:33
  • 13
    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. Commented Dec 22, 2015 at 19:20

4 Answers 4

416

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

6
  • 149
    You can also use ; to repeat the operation and use , to repeat it in opposite direction.
    – Rsh
    Commented Jun 15, 2014 at 5:46
  • 17
    This only seems to work with matches on the same line for me. Commented Mar 25, 2016 at 17:30
  • 16
    @JpajiRajnish Yes. Use /<character> to match it anywhere. Commented 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
    Commented 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
    Commented Dec 4, 2020 at 15:45
80

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:

2
  • 4
    Is there a way to move to right after the colon?
    – james
    Commented Mar 16, 2022 at 4:19
  • 1
    @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
    Commented Jun 25, 2023 at 16:57
13

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

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 and acknowledge you have read our privacy policy.

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