I understand that vi has shortcut keys to delete characters, words and lines with various options.

However, I could not find this:

  • delete from the cursor to the next specified character

For example, I might type du" expecting the editor to "delete until the next " character is found"

The closest I know is d9w where 9 is the number of words to delete.

Does anyone know if this is possible?

  • 2
    If you're interested in Vi and Vim, they have their own SE site now: Vi and Vim – dessert Jan 9 '18 at 16:35

Use dtc, where c is any character, e.g. for you, you want dt"

This will delete upto but not including c.

If you had:

delete until exclamation point!

And the cursor was at the first space and you typed dt!, you would get:


Also dfc.

This will delete upto and including c.

Using df! on the same example above would give you:


Just about any "motion" can be used for the d, c, y and similar commands.

| improve this answer | |
  • 8
    Presumably the mnemonic is t for "till"? Nice answer. – overthink Mar 5 '15 at 17:01
  • 21
    You can also delete to the previous instance of a character with the capitalized version of the movement commands. Maybe more useful for commas -- dT, and dF,. – joelostblom Apr 28 '15 at 14:53
  • 4
    This doesn't work over multiple lines. – 0xcaff Dec 29 '15 at 22:41
  • 3
    Can this be done over a range of lines? – Ray Aug 3 '17 at 17:17
  • 3
    For doing something similar over a range of lines, a usual search (as in zpletan's answer) can be performed: d/word searches up to word. It must be followed by enter (to close the search). – Eric O Lebigot May 21 '18 at 11:15
  • To delete forward up to character 'X' type dtX

  • To delete forward through character 'X' type dfX

  • To delete backward up to character 'X' type dTX

  • To delete backward through character 'X' type dFX

| improve this answer | |

The input dt# (not a :command, use it like a movement like G)

will delete from the cursor until but not including the #. You can substitute any char for #.

| improve this answer | |
  • 2
    This is the right answer! df# will delete # as well. – Viet Dec 23 '14 at 15:30
  • been looking for this, this is awesome – Nadeem Khedr Apr 3 '15 at 7:29

It looks like @Arcege already answered the question, but I did d/l to delete until the character l; other characters would work as well.

| improve this answer | |
  • 3
    This works for stuff across newlines. – jasonszhao Sep 9 '16 at 3:11
  • 1
    Note: this must be followed by Enter. – Eric O Lebigot May 21 '18 at 11:13
  • d?l to delete backwards – Hipponax43 Mar 10 at 16:59

w moves to the following word. l moves to the following charactor.

So it's d9l to delete the next 9 characters.

| improve this answer | |
  • 3
    Close, l is Vim's right arrow key, so you're actually deleting right. Conversely, d9h would delete 9 characters left. – Walf May 30 '16 at 2:24

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.