Cut whole line

You can use C-k to cut (kill in emacs terminology) the text up to the end of the current line from the current cursor position, but this does not include the newline character at the end of the line.

I find it more useful to use C-S-backspace which cuts the whole line including the newline, regardless of where the cursor is.

In either case, the line(s) that you deleted are in your clipboard (kill-ring in emacs terminology) and can be pasted elsewhere (yanked in emacs terminology).

Even more useful, if you add the following code (taken from emacs-fu) to your emacs config file, then pressing C-w (which usually cuts a highlighted region) when no region is highlighted, will cut the current line instead.

;; kill line if no region active                                          ;;
(defadvice kill-region (before slick-cut activate compile)
  "When called interactively with no active region, kill a single line instead."
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
           (line-beginning-position 2)))))
  • Ting-Yu Lin

    If you want to kill a line including the newline character by C-k when your cursor is at the start of the line, set kill-whole-line to t.

    • I didn’t know that – thanks!

    • Ben Maughan

      I didn’t know that – thanks!

  • nitishch

    If you want to copy the current line (save the current line to kill-ring without killing it), replace `kill-region` with `kill-ring-save`. Then, if no region is selected `M-w` will copy the current line