Search code examples
vim

Vim - Delete til last occurrence of character in line


I'm trying to figure out how to dt or df the last occurrence of a character in a string.

For example, let's say I have the following line:

foo not.relevant.text.bar

If I f df. I expectedly get:

foo relevant.text.bar

but I would like to get:

foo bar

Using f 3df. is not an option as I don't know how many of that character will be in the string. Additionally, I may want to get:

foo .bar

or if the line ends with a dot, I may want to get:

foo

In other words I want to always find the last one regardless of how many there are.

Is this possible without a regex? I suppose I could use a regex but I was hoping there was a simple vim command that I'm missing. I find myself trying to do something like this often.


Solution

  • You can use my JumpToLastOccurrence plugin. It provides ,f / ,F / ,t / ,T commands that do just that.