What do the f and t commands do in Vim?

前端 未结 5 1167
青春惊慌失措
青春惊慌失措 2021-01-29 21:12

Can somebody explain to me what the f and t commands do in vim and exactly how they work? I can\'t seem to find this information but people keep telling me

5条回答
  •  再見小時候
    2021-01-29 21:40

    Your first stop with questions like these should be vim's internal help, :h f and :h t. However, in this case, those entries are a bit cryptic without an example. Suppose we had this line (^ = cursor position):

    The quick brown fox jumps over the lazy dog.
    ^
    

    These commands find characters on a line. So fb would place the cursor here:

    The quick brown fox jumps over the lazy dog.
              ^
    

    t is like f but places the cursor on the preceding character. So tb would give you:

    The quick brown fox jumps over the lazy dog.
             ^
    

    You can remember these commands as find and till. Also, you can prepend the commands with a number to move to the nth occurrence of that character. For example, 3fb would move to the third b to the right of the cursor. My example sentence only has one b though, so the cursor wouldn't move at all.

提交回复
热议问题