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

vim
13,593

Solution 1

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.

Solution 2

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

Solution 3

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.
Share:
13,593

Related videos on Youtube

daisy
Author by

daisy

Updated on September 18, 2022

Comments

  • daisy
    daisy over 1 year

    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.

  • Bernhard
    Bernhard over 11 years
    Anybody an idea on how to escape a space in the code-tics?
  • daisy
    daisy over 11 years
    +1 for dt, d t space worked for me
  • Scott Jibben
    Scott Jibben over 11 years
    Just use the same convention as the Vim help file: d/<Space>.
  • Parsa
    Parsa over 9 years
    dE deletes to the end of the WORD
  • Wildcard
    Wildcard over 8 years
    It does exactly and precisely what the O.P. requested.
  • muru
    muru over 8 years
    Holy smokes! It does? I can't believe it!
  • Wildcard
    Wildcard over 8 years
    Oh. I suddenly understand the sarcasm...I didn't realize how old this question was when I posted. Sorry, I'm new here.... :(
  • muru
    muru over 8 years
    Posting to an old question is not a problem. But posting a command without any explanation is.
  • Wildcard
    Wildcard over 8 years
    Got it, good to know.