Emacs 不将M-Del删除的单词加入粘贴板

原文:https://jblevins.org/log/clipboard

I use a clipboard manager called Copied that syncs previously copied text across all my devices. Short of having an OS X version of Drafts, this is a very efficient way to get text from a Mac to an iOS device. However, when I’m working in Emacs, my clipboard history quickly becomes cluttered because every bit of text I “kill” in Emacs gets “copied” to the system pasteboard and then synchronized to all of my devices.

Indeed, every time I select a sentence or paragraph and kill it with C-w (kill-region), that text gets added to the clipboard history. Worse still, every time I press M-DEL (backward-kill-word) to kill the previous word, that word also gets added to my history. I use these commands a lot, so even with a history of 100 previous items, the important items in my history are quickly buried under a heap of words and phrases that I have killed in Emacs during the normal process of writing and editing text.

This is mitigated to some extent by the fact that Copied allows one to quickly filter the history by just typing a search string in the main window. However, I discovered today that Emacs has a minor mode called delete-selection-mode and when this mode is active, the region is replaced when a character is inserted or deleted (e.g., with backspace). The practical implication of this is that one can remove the active region by pressing DEL rather than C-w:

By default, text insertion occurs normally even if the mark is active–for example, typing a inserts the character ‘a’, then deactivates the mark. If you enable Delete Selection mode, a minor mode, then inserting text while the mark is active causes the text in the region to be deleted first. To toggle Delete Selection mode on or off, type M-x delete-selection-mode.

Source: GNU Emacs Manual, section 11.3.

Also see DeleteSelectionMode on the EmacsWiki and in the Emacs FAQ. To summarize, if one uses DEL instead of C-w to remove text in the active region, it won’t end up in the kill ring or clipboard history. Somehow this slipped by me, but delete-selection-mode is enabled by default in Emacs 24 and 25.

Replacing M-DEL with an alternative that deletes without adding to the kill ring is less obvious. Without adding a custom function, a long version would be C-SPC M-b DEL. This sequence activates the mark1, moves the point backward by one word, and deletes the active region. If you find yourself using this often, it might be better to define a backward-delete-word function to your init.el (source):

(defun backward-delete-word (arg)
  "Delete characters backward until encountering the beginning of a word.
With argument ARG, do this that many times."
  (interactive "p")
  (delete-region (point) (progn (backward-word arg) (point))))

I moved the default backward-kill-word binding to C-M-DEL and set M-DEL to this new function:

(global-set-key (kbd "C-M-<backspace>") ‘backward-kill-word)
(global-set-key (kbd "M-DEL") ‘backward-delete-word)

原文地址:https://www.cnblogs.com/cobbliu/p/9835349.html

时间: 2024-11-11 07:11:30

Emacs 不将M-Del删除的单词加入粘贴板的相关文章

按一下删除键删除整个单词

在文本框倒叙输入一文中提到了设置文本框焦点的javascript代码,今天就使用这段代码来做一个Demo.内容就是当删除单词时就一次性删除整个单词,如图所示: 下面我把示例代码贴上: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <meta http-equiv="Content-Type" content="text/html;charset=

Python对象引用和del删除引用

1.首先介绍下python的对象引用 1). python不允许程序员选择采用传值还是传引用.Python参数传递采用的肯定是"传对象引用"的方式.实际上,这种方式相当于传值和传引用的一种综合.如果函数收到的是一个可变对象(比如字典或者列表)的引用,就能修改对象的原始值--相当于通过"传引用"来传递对象.如果函数收到的是一个不可变对象(比如数字.字符或者元组)的引用,就不能直接修改原始对象--相当于通过"传值'来传递对象. 2). 当人们复制列表或字典时,

linux vim 的使用快捷键之删除、复制、粘贴

删除 x    小写的x表示向后删除一个字符,也就是删除光标所在字符 nx  n表示数字,表示向后删除每个字符,例如:10x表示删除包括光标在内的后面10个字符 X    大写的X表示删除光标前的一个字符,不包括光标所在字符 nX  n表示数字,表示向前删除每个字符,例如:10X表示删除光标前的10个字符,不包括光标所在字符 dd      删除光标所在的行,其实也是剪切 ndd    n表示数字,删除光标所在的向下n行 d1G   删除光标所在行到第一行数据 dG     删除光标所在行到最后

iOS——文件操作NSFileManager (创建、删除,复制,粘贴)

iOS——文件操作NSFileManager (创建.删除,复制,粘贴) iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视频等内容.iOS应用产生的内容,如图像.文件.缓存内容等都必须存储在自己的沙盒内.默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.Library包含Caches.Preferences目录.               上面的完整路径为:用户->资源库->Applicat

统计字符串中的删除的单词个数

public class Demo24 { public static void main(String[] args) { String s = "woaijavahahajavaaiwo"; //原来字符串的长度 int length = s.length(); //删除后的长度 int replace = s.replace("java", "").length(); //删除的总长度 int x =length-replace; //单个

列表:remove/del删除方法中的逻辑“误区”

结果: list_1=["A","B","C","D","E","F","G","H"] for i in list_1: list_1.remove(i) print(list_1) 原文地址:https://www.cnblogs.com/Python-T/p/9382966.html

html基础 strong em del ins 粗体 斜体 加删除线 加下划线

礼悟:    公恒学思合行悟,尊师重道存感恩.叶见寻根三返一,江河湖海同一体.          虚怀若谷良心主,愿行无悔给最苦.读书锻炼养身心,诚劝且行且珍惜.              ide:visual studio 2017             browser:Chrome / Firefox                     os:win7 代码 <!DOCTYPE html> <html> <head> <title></tit

Emacs教程(三)

上回说到怎么在Emacs中移动光标,这回将介绍如何在Emacs中编辑文本.任何一款文本编辑软件的核心功能当然就是编辑文本,Emacs也不例外,虽然它也有许多其它强大的本领,但都离不开文本编辑.闹,文本编辑说白了也就是打字,专业点说我们需要实现一种所见即所得输入方式.在Emacs中打字和Notepad中没什么区别,一样也是打开一个文件直接往里面敲字符就可以了,中文也行.这个和Vim区别比较大,我们还需要知道自己是在哪个模式下,不然乱敲一气也不见屏幕有什么反应. 一.文件操作 刚才我们说到编辑文本就

Emacs 从入门到精通

1 前言 不想再说废话了,既然你会阅读这篇文档,说明你多少对Emacs有 些兴趣,或者已 经非常熟悉Emacs的基础操作了,并且希望有所提高.因此我不需要再把"编辑器 之神,还是神的编辑器"之类的恶俗话语放出来,来吸引你的好奇心.下面的内容, 从最基础的快捷键操作开始,一直到让你生活在Emacs中.这中间没有跳跃,你只 需要跟着我做,就可以了. 注意 该文档就是用Org生成的,我会把.org源码和html文档一块打包.关于 什么是Org,怎么生成,且看后面的讲解 2 Emacs 基础操