delete line backwards (Emacs)
This is probably 开发者_运维问答basic but I really tried to find the answer. "C-k" deletes from the cursor to the end of the line, but is there an analogous shortcut to delete a line backwards from the cursor point? Best
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.
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.
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
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
That's not exactly to the beginning of a line, but you might want to check out the hungry-delete
package. Install, then add the following to the init file:
(add-hook 'after-init-hook (lambda ()
(require 'hungry-delete)
(global-hungry-delete-mode)))
After that DEL would delete up to the next non-whitespace character, and so would Backspace, but in the opposite direction.
M-0C-k (because C-0C-k doesn't work on my computer).
To delete all blank spaces in the beginning of a line:
M-mM-0C-k.
精彩评论