This page tells you how to set emacs to kill (cut/delete) a whole line, and discuss some efficiency issues.
To delete a whole line, call
kill-whole-line 【Ctrl+⇧ Shift+⌫ Backspace】.
You can give it the same key as
kill-line, to replace it. 〔☛ Emacs Keybinding Syntax Examples〕
You can also set the Cut command (
kill-ring-save 【Alt+w】) to cut the whole line when there's no selection. See: Emacs: How to Copy/Cut Current Line.
Thanks to Mark Hepburn (), and Dave Pawson ().
[the following is written in as a blog on some efficiency issues. It remains here as a historical archive.]
I've been using the ErgoEmacs Keybinding for 3 years now, and have spent hundreds of hours thinking about efficiency of commands and key choices. Today, it came to my mind that a key to delete the whole line, is actually quite useful. Because, i noticed that i'm tired of having to move cursor to beginning of line first then kill. The problem is made worse by the fact that
kill-line does not kill the line ending. So, to delete a line in emacs, you have to move cursor to the beginning first, then do
kill-line twice, a total of 3 operations. In GNU Emacs, the key presses are【Ctrl+a Ctrl+k Ctrl+k】. (In vi, it is just a single operation, done by pressing 【d d】.)
So, personally, i made a key to kill the whole line. Like this:
(global-set-key (kbd "M-9") 'kill-whole-line)
For a command that deletes a line, there are several issues.
The problem with including the ending newline char when deleting a line is that, when you paste the line, often you do not want the newline char as part of the paste. I have not made statistical study of this. This is just my gut feelings.
Suppose that my assumption about the ending newline issue is correct,
then it could be fixed. When deleting a whole line, the “kill-ring”'s
copy do not include the line ending, except when there are multiple
kill-line operations. Of course, this solution is getting
complicated, breaks the consistency of how deleted text is copied to
the “kill-ring”. So, overall, i think this isn't a solution.
Also, now consider keyboard shortcuts. Key spots are precious.
Line deletion related commands that we can consider to add a key
kill-whole-line}, and also a
version of each that includes the line ending char except
kill-line-backward, so there are total of 5 commands. Let's say only 2
of these commands can have prime key spot, which 2 should we
This requires some research. For example, by starting with myself. Pick 2 commands and try them for 2 weeks. Do this for all possible 2 choices out of the 5. Generally, this research can be done in some scientific way by statistical means, with lots of people.
ErgoEmacs, there are 2 keys to delete line, they are simply
kill-line-backward, with key 【Alt+g】, and 【Alt+⇧ Shift+g】. The
kill-line do not include line ending char.
Perhaps, a alternative choice would be
kill-whole-line with line ending char at
From my experience,
kill-line-backward isn't frequently used, and
kill-whole-line is more frequently needed than
kill-line. So, i think that emacs would have been more efficient if
kill-line's semantic was “kill-whole-line.”
Now having spend a hour writing this out, i think it's actually worth-while to try remapping
kill-whole-line to test things out. But, this would be a pain, because then i'll have to spend weeks changing my muscle memory, and if things didn't work out, i'll have to change and relearn back. And if i found
kill-whole-line to be more efficient than
kill-line, i probably won't change ErgoEmacs keybinding because that would break some compatibility issue with emacs. So, this would be mostly to satisfy a curiosity. For now i'll just see how my 【Alt+9】 works out.
Another related issue is that, emacs's text deleting commands automatically place deleted text into its clipboard the “kill-ring”. This is different from modern text editors, which only put things in clipboard when user explicitly calls the copy command. In the past i've wondered if this emacs way is actually more efficient. I made some study of it, reported here: The Operative Efficiency of Emacs's Deleting Text to “kill-ring”.Disqus