Cut or copy current line with easy-kill

I’ve previously written about how to cut the current line without selecting it, using some custom lisp code. I’ve since noticed that my recommended setup, prelude already deals with this in a nicer way by using the package easy-kill. If you don’t use prelude, then install easy-kill and add

(global-set-key [remap kill-ring-save] 'easy-kill)

to your emacs config file.

Once you have done this, then C-w with no region selected will cut (kill) the current line, and M-w with no region selected will copy the current line. This is one of those neat shortcuts I use all the time and miss whenever I have to edit text outside of emacs!

The easy-kill package also offers the easy-mark function, that expands highlighted regions by word, line or other useful units, but I prefer expand-region for this purpose.

  • Skywalker

    I prefer `C-k` and `M-k` for these actions, but I am not satisfied with the behavior of `C-w` / `M-w` when the region is inactive either, so I might give it a try.

    • Ben Maughan

      I didn’t make it clear above, but a difference is that the easy-kill versions kill from the start of the line regardless of where the point is, while C-k and M-k kill from the point to the end of the line/sentence. I find I still use both.

      • Skywalker

        Ooh indeed!

        Well, `M-k` isn’t bound by default (or is it now?), but indeed the natural implementation is from point to end of line. And I can’t think of any case where I’d want that instead of `M-w`, come to think of it.

        Love this kind of “simple things that you didn’t realize you needed” posts, thanks!