views:

174

answers:

1

What is the emacs equivalent of vi's dd? I want to delete the current line. Tried CTRL + k but it only deletes from current position.

+14  A: 
C-a # Go to beginning of line
C-k # Kill line from current point

There is also

C-S-backspace   # Ctrl-Shift-Backspace

which invokes M-x kill-whole-line.

If you'd like to set a different global key binding, you'd put this in ~/.emacs:

(global-set-key "\C-cd" 'kill-whole-line)     # Sets `C-c d` to `M-x kill-whole-line`

If you want to delete a number of whole lines, you can prefix the command with a number:

C-u 5 C-S-backspace   # deletes 5 whole lines

C-u C-S-backspace     # delete 4 whole lines. C-u without a number defaults to 4

C-u -5 C-S-backspace   # deletes previous 5 whole lines

Sometimes I also find C-x z helpful:

C-S-backspace         # delete 1 whole line
C-x z                 # repeat last command
z                     # repeat last command again. 
                      # Press z as many times as you wish. 
                      # Any other key acts normally, and ends the repeat command.
unutbu
This works. Is there a way to do this using one command? Will I have to create a custom key binding to do this?
Manoj Govindan
Didn't know `C-x z`, that's really cool. And nice and precise answer btw.
slu