delete line backwards (Emacs)

Here's asjo's answer bound to a key:

(global-set-key "\M-k" '(lambda () (interactive) (kill-line 0)) ) ;M-k kills to the left

As other answers suggest, C-0C-k kills from point to the start of the line. See the documentation for C-k (kill-line) for more information. You may also want to kill the whole line before and after point with C-S-backspace which evals kill-whole-line.

Another convenience for killing is to rebind kill-region which defaults to C-w and instead bind to that key the function backward-kill-word which will then mimic the behavior of readline's C-w (unix-word-rubout). I rebind kill-region to C-q after moving quoted-insert to A-q. Yes, this requires moving a number of keys around, but if you give it a try I think you'll find it is convenient.


Try C-u 0 C-k - i.e. C-k with the prefix 0 kills from point to the start of the line. See the documentation for C-k (kill-line) for more information.


I tried C-u with a negative number and C-k as arguments. It worked.
Example to delete 4 lines before cursor, try C-u -4 C-k

Tags:

Emacs