0

Say we got this sentence:

pafpaf apfa fpa i apa panda pafas af

I would like to quickly move the cursor from the start of the line to the beginning of the word panda. I could do 6fp, but what takes time is counting the number of p's. It would be much faster if I simply could search for the word in the current line and instantly jump to it.

Now, I could just do a search for it: /panda hit enter and then :noh (to remove highlighting), but having to write out :noh every time is annoying and time-consuming.

Does anyone have any suggestion for a solution?

4
1

I use a mapping <LEADER>/ so I can toggle highlighting on and off:

nnoremap <silent><expr> <LEADER>/
            \ (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n"

I found that the above would highlight the last searched term when I opened vim, which I found irritating, but I fixed that by adding | noh to the setting hlsearch:

set hlsearch | noh " highlight matches for searched (turn off when sourcing)

Also it's worth mentioning that after using fp (or Fp, tp, Tp etc.) you can use ; and , to jump to the next occurrence of 'p' (or whatever you searched for). So in cases where you do a f motion, and don't jump right to the letter you want because you didn't notice that same letter occurring sooner, you can just hit ; a few times to get there...

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.