退格键不加杀环


12

使用Crtl + Backspace或Ctrl + Del可将删除的文本添加到kill ring。
如何防止这种情况发生?删除时,我不需要将所有文本发送到kill ring。

补充问题:此默认设置的目的是什么?:)


关于附带的问题:可能需要备份您删除的内容而无需进行操作undo。不过,大胆猜测。
Manuel Uberti

Answers:


7

根据文档:

<C-delete>运行命令kill-word(位于global-map中),该命令是中的交互式已编译Lisp函数‘simple.el’

它必然<C-delete>, M-d

(杀手ARG)

向前杀死字符,直到遇到单词结尾。对于参数ARG,请执行多次。

现在,让我们浏览源代码:

(defun kill-word (arg)                                                                                                     
  "Kill characters forward until encountering the end of a word.                                                           
With argument ARG, do this that many times."
  (interactive "p")
  (kill-region (point) (progn (forward-word arg) (point))))

然后,在该kill-region功能的文档中找到:

在点和标记之间杀死(“剪切”)文本。
This deletes the text from the buffer and saves it in the kill ring。命令[yank]可以从那里检索它。(如果要保存区域而不杀死它,请使用[kill-ring-save]。)

[...]

Lisp程序应使用此功能来杀死文本。(要删除文本,请使用delete-region。)

现在,如果您想走得更远,可以使用以下功能来删除而不复制到kill-ring:

(defun my-delete-word (arg)
  "Delete characters forward until encountering the end of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
  (interactive "p")
  (delete-region
   (point)
   (progn
     (forward-word arg)
     (point))))

(defun my-backward-delete-word (arg)
  "Delete characters backward until encountering the beginning of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
  (interactive "p")
  (my-delete-word (- arg)))

(defun my-delete-line ()
  "Delete text from current position to end of line char.
This command does not push text to `kill-ring'."
  (interactive)
  (delete-region
   (point)
   (progn (end-of-line 1) (point)))
  (delete-char 1))

(defun my-delete-line-backward ()
  "Delete text between the beginning of the line to the cursor position.
This command does not push text to `kill-ring'."
  (interactive)
  (let (p1 p2)
    (setq p1 (point))
    (beginning-of-line 1)
    (setq p2 (point))
    (delete-region p1 p2)))

; bind them to emacs's default shortcut keys:
(global-set-key (kbd "C-S-k") 'my-delete-line-backward) ; Ctrl+Shift+k
(global-set-key (kbd "C-k") 'my-delete-line)
(global-set-key (kbd "M-d") 'my-delete-word)
(global-set-key (kbd "<M-backspace>") 'my-backward-delete-word)

ErgoEmacs提供


谢谢,解决了。那副问题呢?:p
Daniel Hitzel '16

3
@DanielHitzel抱歉,我没有附带问题的答案:)
Nsukami _

所以我并不孤单:D
丹尼尔·希策

4

从Emacs 24开始,没有任何配置,您可以选择任何文本,然后按Backspace或来删除任何文本而不将其添加到kill ring Delete。当标记处于活动状态时,这些键将删除区域,而不仅仅是删除光标之前/之后的字符。

也就是说,移至要删除的文本的一端,按Ctrl+ Space,移至另一端,然后按Backspace(或Delete)删除突出显示的区域。或移至一端,Shift在使用移动键移至另一端时按住,然后按Backspace


好吧,在MacOS中使用Emacs 25.1的情况并非如此。
NVaughan '16

0

我遇到了同样的问题,可以通过以下方式更轻松地解决它:

(global-set-key (kbd "<backspace>")
          '(lambda () (interactive) (backward-delete-char-untabify 1 nil)))

调用(backward-delete-char-untabify 1 nil)告诉Emacs向后删除一个字符(这是1参数),并避免复制到环(这是nil参数)。您需要一个lambda(即匿名)函数,因为您要将具有参数的函数绑定到键。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.