- How to delete a word to the left? In other words, to delete the word when cursor stands at the end of it.
- How to delete characters to the beginning of the line?
How to delete to the first whitespace to the left?
Other tricks involving word deletion
views:
170answers:
6
+2
A:
In command mode:
bdw
, back delete word.d^
(to the first non-blank),d0
(to the first character)BdW
(go to first whitespace delete to next whitespace)
(Community wiki, feel free to hack.)
zoul
2009-09-03 14:46:14
Here you go: 3. BdW
Corey D
2009-09-03 14:52:29
+1
A:
In insert mode:
- ^w
- ^u
- can't answer out of my head ;-)
Otherwise:
- dw
- v0x
- can't answer out of my head ;-)
Michael Krelin - hacker
2009-09-03 14:50:05
A:
/ <CR>x
(search forward for a space, hit enter to go there, x to delete)
There may be a more magic way of doing it, but I don't know of one.
inkedmn
2009-09-03 14:50:21
If you want to delete the first whitespace to the left, hit ? instead of / in my example.
inkedmn
2009-09-03 14:50:53
+5
A:
db
(if the cursor is after the word) orbdw
d0
(ord^
if you want to delete to the first non-blank character)dE
or dtSpace to delete to the first space or d/\sEnter to delete to the next white space character.
Edit
Since the question has been changed such that 3 is delete to the first whitespace character to the left, my answer should change to:
dB
or dShiftTSpace to delete back to the first space or d?\sEnter to delete to the previous white space character.
See:
:help motion.txt
:help WORD
Al
2009-09-03 14:51:05
Good call on #3. I wasn't sure how to handle ANY whitespace. It's worth mentioning that dF<SPACE> will delete up to and including the <SPACE> while dT<SPACE> will leave the <SPACE> there.
Mark Biek
2009-09-03 14:54:19
+2
A:
In general, d<motion> will delete from current position to ending position after <motion>. This means that:
- d<leftArrow> will delete current and left character
- d$ will delete from current position to end of line
- d^ will delete from current backward to first non-white-space character
- d0 will delete from current backward to beginning of line
- dw deletes current to end of current word (including trailing space)
- db deletes current to beginning of current word
Read this to learn all the things you can combine with the 'd' command.
Lucas Oman
2009-09-03 15:01:58