tags:

views:

449

answers:

5

Often when developing I am confronted with a nested object that I'd like to delete from code in the middle of a line like this:

htmlDoc.WriteLine("<b><h3>" + this.cbAllSyncs.SelectedItem.ToString() + "</h3></b>");

The part that I'd like to delete is:

this.cbAllSyncs.SelectedItem.ToString()

I know I can count the number of words and periods and enter "7dw" to delete from my current cursor position of "this". However, what I'd love to do is not have to count at all and delete to the space with one command. Is this possible?

By the way, I love VI! I've been using it for about three or four months and it has changed my programming for the better. Many kudos to the developer at my job who insisted I learn.

+13  A: 

Try dtspace. In general dtx deletes from current position till x. Just tx can be used to reach character x in current line.

This works great! It also gives me some added flexibility to get to other certain points within that object. Thanks!
Blake Blackwell
`df<space>` deletes upto and including the next space.
glenn jackman
equally useful, dfT<space> deletes downto the previous space.
hgimenez
You can also add a count just before the `t` to delete up to that many characters. e.g. `d2t<space>` will delete up to two spaces.
Waseem
+10  A: 

You can use dW or dE as @glenn suggested if you don't want to delete the space itself.

A WORD (uppercase W) consists of a sequence of non-blank characters, separated with white space.

Give a look to the word motions.

CMS
If I could vote for two answers I would, since this resolves the specific question I asked. Thanks for the link!
Blake Blackwell
or `dE` -- delete until the end of the sequence of non-blank characters (does not include the following blank)
glenn jackman
+2  A: 

one possible solution is to use the delete with a search.

so type in d/<space> and vim will delete until it hits a space.

barkmadley
This is more general than `dW` because you can also use it to delete from the cursor to any character, such as `2d/+`, in this case -- which would delete the String concatenations as well.
Dave Jarvis
you can do 2dW and this performs just as well. in fact I consider it a better solution since it will also work with tabs and other whitespace. It also removes the trailing whitespace you want to delete until.
barkmadley
A: 

"dt " is the answer to your question, but "df+" looks like it will solve your problem better.

Dan Goldstein
A: 

If you want to delete from anywhere inside the WORD, and in a single command, just use daW

(you can of course use daw if you want to limit to a word)

I use it quite a lot because it spare a move to the begining of the word (in your case)

Louis