# Emacs: Deleting a line without sending it to the kill ring

I would like to use C-k to delete a line without sending it to the kill-ring.

I have the following on my .emacs file

(delete-selection-mode 1)


but this only seems to work for C-d (delete-char)

I have also read the solutions described in this thread: Emacs: how to delete text without kill ring?, but I didn't see anything that addresses this precise problem.

-
Why does it matter if it goes to the kill ring? –  psusi Dec 8 '11 at 23:30
@psusi: Quite often I copy some text and then kill several lines one by one before yanking. When yanking, I don't remember how many lines I killed, and cycling through the kill ring to find the text I want to yank can be distracting. Either way, I'm also interested in learning how this can be done. –  user815423426 Dec 8 '11 at 23:40

(defun delete-line (&optional arg)
(interactive "P")
(flet ((kill-region (begin end)
(delete-region begin end)))
(kill-line arg)))


Maybe this is not the best solution, but it seems works. You may need to bind delete-line' to some global key, such as

(global-set-key [(control shift ?k)] 'delete-line)

-
what exactly is (control shift ?k) ? I copied the line verbatim in my .emacs file and tried using the CTRL+SHIFT+k keystroke and it didn't seem to work. –  Marcus Junius Brutus May 30 '14 at 20:10
Depending on the window-system (esp. terminal), control+shift+k may not work. To test for specific key-binding is available, use C-H k, then type the keybinding whether it works. –  cinsk Jun 9 '14 at 1:05
this kills only to the end-of-line. How about killing the whole line, but keeping the current cursor column? –  towi Nov 17 '14 at 12:26

cinsk answer did not work for me on emacs 24.

But this did:

;; Ctrl-K with no kill
(defun delete-line-no-kill ()
(interactive)
(delete-region
(point)
(save-excursion (move-end-of-line 1) (point)))
(delete-char 1)
)
(global-set-key (kbd "C-k") 'delete-line-no-kill)
`
-