emacs how to define hotkey C-u to Delete from current position to the beginning of line

StackOverflow https://stackoverflow.com/questions/19042999

  •  29-06-2022
  •  | 
  •  

Question

I hava know C-u 0 C-k could do that thing, but I really want use C-u delete from current position to the beginning of line just like the bash readline.

Was it helpful?

Solution

No, you really don't want to do that -- trust me. C-u is far too important in Emacs to be used for something else. And to substitute a different key for what C-u does would be a pain and troublesome for you in the end, IMHO.

Instead, find some other key that you're comfortable with and assign that to a command that does what you want. For example, rebind a key that is already bound to a command that you don't really care about (e.g. M-k).

For example:

(defun kill-to-bol ()
  "Kill text from point to beginning of line."
  (interactive)
  (kill-region (point) (line-beginning-position)))

(global-set-key "\M-k" 'kill-to-bol)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top