How to delete the current line in Emacs

emacs

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.

Best Answer

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
M-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
M--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.