在 Emacs 中将选择的文本包裹在封闭字符中
在 Textmate 中,我可以通过选择文本并点击开头字符来将封闭字符('('、'['、'"' 等)包裹在文本周围。例如,如果我选择 word
并点击(
,它将变成 (word)
。Emacs 将此功能称为什么以及如何启用它?
In Textmate I can wrap enclosing characters ('(', '[', '"', etc.) around text by selecting it and hitting the opening character. For example, if I select word
and hit (
, it will become (word)
. What does Emacs call this feature and how do I enable it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您使用 smartparens,只需选择文本,然后输入该对。 Smartparens wiki:包装
If you use smartparens just select the text and then type the pair. Smartparens wiki: Wrapping
对于括号,您可以执行 M-(。对于括号/大括号/引号,您可以执行以下操作:
请注意,如果您没有突出显示区域,它只会插入一对任意内容并将光标放在在它们之间,删除匹配的内容也很方便
编辑:
关于覆盖
backward-paragraph
的评论很好,您可以将其绑定到C-{< /kbd>,这可能会干扰主要模式中的某些内容,并查找最后一个键并查找要插入的对,因此如果您不想将其绑定到。 something-{ 你可以绑定到这个函数:For parens you can do M-(. For brackets/braces/quotes you could do:
Note that if you don't have a region highlighted, it will just insert the pair of whatevers and put the cursor in between them. Also handy for deleting matching whatevers is
EDIT:
Good point in the comments about overriding
backward-paragraph
. You could bind it to C-{, which might interfere with something in a major mode.insert-pair
takes the last key and does a lookup to see what pair to insert, so if you don't want to bind it to something-{ you could bind to this function instead:自 Emacs 24.1(2012 年 6 月发布)起。
将其放入您的 emacs init 中:(electric-pair-mode 1)。
现在,如果你选择一个单词并点击 (,它将变成 (单词)。“、[、{ 等”也一样。
Since Emacs 24.1(released 2012-06).
Put this in your emacs init: (electric-pair-mode 1).
Now If you select a word and hit (, it will become (word). Same for ", [, { etc.
我使用 http://www.emacswiki.org/emacs/ParEdit。 M-( 正是这样做的。
I use http://www.emacswiki.org/emacs/ParEdit. M-( does exactly this.
Autopair 是这些工具中最好的一个
Autopair is the best one of these tools
您可以查看 wrap-region。
You can have a look at wrap-region.
我也会看看骨架模式
http://ggorjan.blogspot.com/2007/05 /sculpture-pair-mode-in-emacs.html
它非常灵活,特别是对于括号。
I'd take a look also at skeleton-mode
http://ggorjan.blogspot.com/2007/05/skeleton-pair-mode-in-emacs.html
It's very flexible expecially for parentheses.
有文本伙伴模式。
来自 Emacswiki:
请参阅 textmate-mode 以尝试对括号和引号使用 TextMate 行为(自动关闭、覆盖、智能删除)。
http://code.google.com/p/emacs-textmate/
There is textmate-mode.
From Emacswiki:
See textmate-mode for an attempt of having the TextMate behaviour for parenthesis and quotes (auto-closing, overwriting, smart delete).
http://code.google.com/p/emacs-textmate/
现在还有Corral。它的“按我的意思做”行为使得这个过程比手动选择文本并按键要快得多。
(免责声明:我是作者)
There's now Corral as well. Its "do what I mean" behavior makes this process a lot faster than manually selecting the text and hitting the key.
(disclaimer: I'm the author)