In Vim, how can I delete all text from the current cursor position until the next space?

In Vim, I know d$, that deletes everything to the end of line.

But how can I delete all text from the current cursor position until the next space? dw doesn’t work, since it treats symbols like colon as separator as well.

Asked By: daisy

||

dW (capital W) or more generally you can do df followed by the character to search for, in this case space. You can also use t instead of f to delete up to but not including the found character. And if you capitalize the F or T, they work backwards.

Answered By: qqx

You can also delete until a search string, thus d/<Space> will delete until, but not including, the first space from the cursor position.

Answered By: Bernhard

The best (fewest keystrokes) way is

dE

This deletes all text from the current position until the next space. From the help (:h E)

                                                        E
E                       Forward to the end of WORD [count] inclusive.
                        Does not stop in an empty line.
...
                                                        WORD
A WORD consists of a sequence of non-blank characters, separated with white
space.  An empty line is also considered to be a WORD.
Answered By: Wildcard
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.