In Vim, how can I delete all text from the current cursor position until the next space?
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.
Related videos on Youtube
Author by
daisy
Updated on September 18, 2022Comments
-
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.-
Admin over 11 years
-
-
Bernhard over 11 yearsAnybody an idea on how to escape a space in the code-tics?
-
daisy over 11 years+1 for
dt
, d t space worked for me -
Scott Jibben over 11 yearsJust use the same convention as the Vim help file:
d/<Space>
. -
Parsa over 9 years
dE
deletes to the end of the WORD -
Wildcard over 8 yearsIt does exactly and precisely what the O.P. requested.
-
muru over 8 yearsHoly smokes! It does? I can't believe it!
-
Wildcard over 8 yearsOh. I suddenly understand the sarcasm...I didn't realize how old this question was when I posted. Sorry, I'm new here.... :(
-
muru over 8 yearsPosting to an old question is not a problem. But posting a command without any explanation is.
-
Wildcard over 8 yearsGot it, good to know.