tags:

views:

170

answers:

6
  • 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

+2  A: 

In command mode:

  1. bdw, back delete word.
  2. d^ (to the first non-blank), d0 (to the first character)
  3. BdW (go to first whitespace delete to next whitespace)

(Community wiki, feel free to hack.)

zoul
Here you go: 3. BdW
Corey D
+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
yes... left...edited
vehomzzz
edited out my observation.
Michael Krelin - hacker
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
If you want to delete the first whitespace to the left, hit ? instead of / in my example.
inkedmn
+5  A: 
  1. db (if the cursor is after the word) or bdw
  2. d0 (or d^ if you want to delete to the first non-blank character)
  3. 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:

  1. 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
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
+2  A: 

In general, d<motion> will delete from current position to ending position after <motion>. This means that:

  1. d<leftArrow> will delete current and left character
  2. d$ will delete from current position to end of line
  3. d^ will delete from current backward to first non-white-space character
  4. d0 will delete from current backward to beginning of line
  5. dw deletes current to end of current word (including trailing space)
  6. db deletes current to beginning of current word

Read this to learn all the things you can combine with the 'd' command.

Lucas Oman
+1  A: 

To answer point #3, diw and daw are excellent.

Randy Morris