16

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.).

  • 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 '15 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 '15 at 20:58
  • 1
    Dahu made a plugin for this: github.com/dahu/vim-fanfingtastic – EvergreenTree Aug 23 '15 at 20:59
  • 1
    I still think the best plugin for this is easymotion – Vitor Aug 25 '15 at 14:12
  • 1
    I also made a plugin: improvedft – Christian Brabandt Aug 25 '15 at 16:55
6

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.

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

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.