Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand that vi has shortcut keys to delete character, word and line with various options. However, I could not find this:

  • to delete from cursor to the next specified character. I might type du" (example) expecting the editor to "delete until the next double quote character is found"

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

Anyone knows if this is possible?

share|improve this question
up vote 134 down vote accepted

Use dfc.

If you had:

delete until exclamation point!

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

delete

Also dtc. This will delete upto but not including c. Using dt! on the same example above would give you:

delete!

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

share|improve this answer
    
Exactly what i was after! Thanks @Arcege! – kctang Oct 8 '11 at 18:02
3  
+1 for the "t" example – Skurpi Mar 4 '15 at 10:12
1  
Presumably the mnemonic is t for "till"? Nice answer. – overthink Mar 5 '15 at 17:01
2  
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,. – cheflo Apr 28 '15 at 14:53
1  
This doesn't work over multiple lines. – caffinatedmonkey Dec 29 '15 at 22:41

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 #.

share|improve this answer
1  
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.

share|improve this answer

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

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

share|improve this answer
    
Close, l is Vim's right arrow key, so you're actually deleting right. Conversely, d9h would delete 9 characters left. – Walf May 30 at 2:24
  • 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.