vim: delete to character, non-inclusive

Vim

Vim Problem Overview


Suppose I'm in a certain line position in vim and I want to delete up to a certain character, say a semicolon. I would do df; except it would also delete the semicolon. Is there a command that will do the same thing but will not include the character I'm searching for?

Vim Solutions


Solution 1 - Vim

Yes, dt;. From the Vim docs:

> t{char} > > Till before [count]'th occurrence of {char} to the right. The cursor is placed on the character left of {char} |inclusive|. {char} can be entered like with the |f| command.

Solution 2 - Vim

To add to what Michal said, you can also use T and F to do the same thing backwards.

Also ; will repeat the last t,T,f or F motion, and ' will repeat it in the opposite direction.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmir RachumView Question on Stackoverflow
Solution 1 - VimMichał MarczykView Answer on Stackoverflow
Solution 2 - VimDave KirbyView Answer on Stackoverflow