Blake Blackwell
Blake Blackwell

Reputation: 7795

VIM: Deleting from current position until a space

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?

Upvotes: 209

Views: 69877

Answers (6)

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 828002

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.

Upvotes: 88

Naseeruddin V N
Naseeruddin V N

Reputation: 625

  • delete for the current position to a specific character example "

    dt"
  • delete the word from the position cursor is on till the end of the word

    dw
  • delete the entire word the cursor is on irrespective of the position the cursor is on the word, this also puts you in insert mode to enable you to insert immediately.

    diw

Upvotes: 12

amit
amit

Reputation: 10902

Try dtspace. In general dtx deletes from current position till just before x. Just tx moves the cursor to just before character x in current line.

To delete up to and including the space, use dfspace.

Upvotes: 416

Louis
Louis

Reputation: 1432

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)

Upvotes: 18

Dan Goldstein
Dan Goldstein

Reputation: 23660

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

Upvotes: 2

barkmadley
barkmadley

Reputation: 5317

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.

Upvotes: 20

Related Questions