You can use kill-whole-line
to kill the entire line point is on. Position of point does not matter. This command is bound to C-S-DEL by default.
You can also instruct kill-line
(bound to C-k) to kill the entire line by setting the variable kill-whole-line
to a non-nil
value:
(setq kill-whole-line t)
Note that point has to be at the beginning of the line for this to work.
Then there are these two gems (via emacs-fu):
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-beginning-position 2)))))
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single line instead."
(interactive
(if mark-active
(list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position) (line-beginning-position 2)))))
With these in place you can kill or copy the line point is on with a single keystroke:
- C-w kills the current line
- M-w copies the current line
Note that if there is an active region, kill-region
and kill-ring-save
will continue to do what they normally do: Kill or copy it.
Porting slick-cut
and slick-copy
to new advice system
Emacs 24.4 introduces a new advice system. While defadvice
still works, there is a chance that it might be deprecated in favor of the new system in future versions of Emacs. To prepare for that, you might want to use updated versions of slick-cut
and slick-copy
:
(defun slick-cut (beg end)
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-beginning-position 2)))))
(advice-add 'kill-region :before #'slick-cut)
(defun slick-copy (beg end)
(interactive
(if mark-active
(list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position) (line-beginning-position 2)))))
(advice-add 'kill-ring-save :before #'slick-copy)
kill-whole-line
. :)evil-mode
. Learn Vim commands, you will not regret!