5

Is there a motion to move to the last of a character?

Example:

[A]pple -> move to last p -> Ap[p]le

I can do that with 2fp but if there's lots of "p"s in the line then it's not so easy to count them then do 10fp

Lerp
  • 2,957
  • 3
  • 24
  • 43
  • 1
    possible duplicate of [Vim - Delete til last occurrence of character in line](http://stackoverflow.com/questions/15249160/vim-delete-til-last-occurrence-of-character-in-line) – Ingo Karkat Oct 14 '13 at 09:23

5 Answers5

7
$Fp

$ jumps to the end of the line, F jumps backwards to the character p.

This does not work if p is your last character.

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
  • This isn't a motion, it won't work with an operator, i.e `d$Fp` – Lerp Oct 14 '13 at 09:02
  • 1
    It's two motions, so if you wanted to delete backwards to the last "p" in the line, it would be $dFp. Deleting everything before the last "p" would be $Fpd0, which you could use as a macro if you needed to repeat it. I don't see a major advantage to having it in a single motion, but maybe someone can explain that to me. – Jeremy Oct 14 '13 at 14:53
  • With `$Fpd0` you can delete everything before the last character, but you cannot delete everything between the cursor and the last character. It would work with visual mode, though. – pfnuesel Oct 14 '13 at 17:20
6

My JumpToLastOccurrence plugin extends the built-in f / F / t / T motions with counterparts (by default bound to ,f etc.) that move to the last occurrence of {char} in the line.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
5

Search from the end

Instead of looking for the last occurrence of a character - move to the end and look backwards for the first:

$Fp
Community
  • 1
  • 1
AD7six
  • 63,116
  • 12
  • 91
  • 123
  • This isn't a motion, it won't work with an operator, i.e `d$Fp` – Lerp Oct 14 '13 at 09:01
  • 1
    Sorry, as a motion you'll need [something like this](http://www.vim.org/scripts/script.php?script_id=3386) afaik. – AD7six Oct 14 '13 at 09:04
4

There's no such motion.

But you could always do vfp;;;;d or v$Fpd.

Or find another more suitable target.

Or use a plugin like Easymotion.

romainl
  • 186,200
  • 21
  • 280
  • 313
1

My Vim plugin improved_ft also allows for this. Set let g:ft_improved_multichars = 1, press f and then type p followed by l.

Christian Brabandt
  • 8,038
  • 1
  • 28
  • 32