vi Editor: Commands: Delete Text
The letter d is the delete operator in vi. Because it is an operator, it has
no effect by itself. It requires a motion command to tell it the scope of the
deletion. As a special case, dd deletes the entire current line.
So, what can we do with this delete operator? Basically, d followed by any
command that would move the cursor deletes text up to and including where the
cursor would have gone for that motion. For example:
- de - delete to end of word
- dw - delete word
- d^ - delete back to beginning of line
- df: - delete until next occurrence of a ':'
- dL - delete to bottom of screen
- d/how - delete up to next occurrence of "how"
- d?^[a-q]*: - delete back to next line which matches "^[a-q]*:"
Deletions are saved in a queue of 10 buffers, numbered 1 through 10. The most
recent deletion is always in 1. You can get back your most recent deletion
with p, and other deletions with "np where " is itself, and n is the number
of the buffer. Therefore, to reverse the order of 3 lines, you could use this
sequence of four commands:
ddddp"2p