20

Is there a way that t{char} and f{char} will continue to work in the next lines if {char} is not present in a given line?

I would like to avoid using /{char}<CR> to save 1 keystroke and to not have search highlighting, especially when I need this in combination with verbs (e.g. dfa, ct.).

7
  • 2
    You can do d/a to delete to the next a and c/. to delete to the next .. If you use hlsearch and don't want it when doing this operation, you can create a mapping which does your d/ operation and then disables the highlighting (ends with :nohlsearch).
    – jjaderberg
    Aug 23, 2015 at 20:49
  • 2
    You could use (or study) a plugin such as github.com/rhysd/clever-f.vim (with g:clever_f_across_no_line set to 0 and other options enabled/disabled at will).
    – VanLaser
    Aug 23, 2015 at 20:58
  • 1
    Dahu made a plugin for this: github.com/dahu/vim-fanfingtastic Aug 23, 2015 at 20:59
  • 1
    I still think the best plugin for this is easymotion
    – Vitor
    Aug 25, 2015 at 14:12
  • 1
    I also made a plugin: improvedft Aug 25, 2015 at 16:55

3 Answers 3

9

I was also using dahu/vim-fanfingtastic for some time and found it very helpful. It supports semantic repeats with . thanks to the library tpope/repeat.vim which you must also install.

An alternative is chrisbra/improvedft which does more or less the same thing.

rhysd/clever-f.vim has an option to enable multi-line seeking, although its primary feature is to allow f to repeat the current seek, like ; does already.

Those all handle ; and , keys as expected.

The disadvantage with multi-line f and t is that if you hit the wrong key, you will be taken off the current line to somewhere unexpected in the file. Ctrl-O can help in those moments. (This can be dangerous with a c change if you don't realise that you just swallowed a few lines, but those were only teething troubles for me.)

There are other related plugins, with slightly different approaches, such as justinmk/vim-sneak and goldfeld/vim-seek which prompt for two characters, making it easier (but still not guaranteed) to hit your target location.

And then there is easymotion/vim-easymotion. This offers a lot of powerful motion keys, some of which require an extra keypress or two to confirm the target character when there are many candidates.


But currently I'm using a home grown solution. I worked with the author of EasyMotion to make f and t flash count markers over all the matching characters ahead of you.

enter image description here

This acts as a natural count assistant for vanilla vim motions. When you try to move somewhere with fx but then discover there are more xs in the way than you thought, you can read the number that flashed over the character you were aiming for, and then do [count]; to jump there.

You can find the branch here. Be sure to read the section Add helpful hinting to set up the key mappings.

However for c change operations, it is still preferable to get it right the first time. In those cases I recommend spending an extra keystroke in v Visual mode, or using one of EasyMotion's guaranteed jumps.

0
2

there is a plugin that does what you seem to be wanting, as stated by VanLaser.

https://github.com/dahu/vim-fanfingtastic

It now requires the repeat plugin to work properly, so you will need that too:

https://github.com/tpope/vim-repeat

2
0

In spacemacs you can use SPC j w {first-char-of-word}.

Although this is different, it has replaced my need for ft across lines. What I do now is use ft for same line searches, and SPC j w for anything else.

As a bonus, you can jump to lines in other visible buffers too! Really convenient for split-window programming.

4
  • 1
    Spacemacs? As in the emacs distribution? I'm not sure how that really qualifies as an answer on Vi and Vim
    – D. Ben Knoble
    Jan 12, 2022 at 14:45
  • Actually you are right. I thought I was on emacs. That said, this answer would've helped me as I frequent Vi and Vim as a spacemacs user.
    – mcp
    Jan 15, 2022 at 22:49
  • It's worth mentioning that spacemacs supports vim bindings, which is why I find myself in this forum often.
    – mcp
    Jan 15, 2022 at 23:26
  • See vi.stackexchange.com/help/on-topic, so I'm not sure if a spacemacs specific mapping is on-topic (it's implementation could be, if it were done with a vi mapping or vimscript or similar).
    – D. Ben Knoble
    Jan 16, 2022 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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