28

Surround.vim是一个漂亮的 vim 扩展,它允许你用 、括号、花括号和几乎任何任意的“环绕”字符包围文本块。它支持段落和单词环绕,但我经常在可视模式下使用它。我正在玩 Emacs,想知道是否有类似的东西;可以让我突出显示一个区域,然后将标记的区域(或矩形)用大括号、方括号或标签括起来。

4

7 回答 7

31

也许wrap-region是您所需要的。

如果需要用分隔符、标签等包装某些东西,smartparens是另一个很好的选择。

于 2010-04-30T19:34:06.717 回答
9

I use evil-surround. It emulates vim behaviour but unfortunately might not be what most emacs users want since it requires the evil vim mode. However, it may or may not be right for you since you referenced surround.vim in the first place.

evil-surround seems to support most of the features in Surround.vim, including modifying surroundings.

于 2012-05-31T07:04:15.383 回答
5

我认为标签没有内置任何东西,但是对于括号你可以做M-(. 对于括号/大括号/引号,您可以这样做:

(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)

请注意,如果您没有突出显示区域,它只会插入一对whatevers并将光标放在它们之间。删除匹配的任何东西也很方便

(global-set-key (kbd "M-)") 'delete-pair)

如果你想插入标签对,这是一些简单的 elisp:

(defun my-insert-tags (tag)
  (interactive "sTag: ")
  (if (region-active-p)
      (let ((beg (region-beginning)))
        (save-excursion
          (goto-char (region-end))
          (insert "</" tag ">")
          (goto-char beg)
          (insert "<" tag ">")))
    (insert "<" tag ">")
    (save-excursion
      (insert "</" tag ">"))))
于 2010-05-01T23:59:52.287 回答
1

不知道在 Emacs 中有什么方法可以做到这一点,即使是模块也不知道。

我的 Elisp 有点生疏了,在这里买一个简单的函数,它将当前区域(标记的文本)或带引号(“)的单词括起来:

(defun 插入引号 ()
  "在当前区域或作品周围插入引号 (\")。"
  (交互的)
  (让(开始结束边界)
    (如果(和瞬态标记模式标记激活)
        (setq start (区域开始)
              结束(区域结束))
      (预测
        (setq bounds (bounds-of-thing-at-point 'symbol))
        (setq start (车界)
              结束(cdr 边界))))
    (转到字符开始)
    (插入 ”\””)
    (goto-char (+ end 1))
    (插入 ”\””)))
于 2010-05-01T10:42:01.477 回答
1

Yes, there is a clone of surround.vim, as of 1 week ago: http://github.com/timcharper/vimpulse-surround.el

It requires vimpulse, which requires vim. It implements much of surround.vim's functionality.

于 2010-07-28T02:17:36.387 回答
1

maybe evil-surround is what you are looking for.

thanks.

于 2014-09-14T15:05:38.220 回答
-3

所以你想选择一个区域或类似的区域,然后在它周围制作一个框,就像各种模式一样用于评论?我相信 emacs-wiki ( http://www.emacswiki.org/ ) 有一些 ascii-line art (和一个 figlet 工具) 可以做到这一点。搜索框,相当,线条艺术......

############################
#                           #
# I AM REGION, WE ARE  MANY #
#                           #
############################
于 2010-04-30T18:47:09.870 回答