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.
The simplest kill command is C-k . If given at the beginning of a line, it kills all the text on the line, leaving it blank. When used on a blank line, it kills the whole line including its newline. To kill an entire non-blank line, go to the beginning and type C-k twice.
Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character.
Delete Selection mode lets you treat an Emacs region much like a typical text selection outside of Emacs: You can replace the active region just by typing text, and you can delete the selected text just by hitting the Backspace key ( 'DEL' ).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With