emacs:更改矩形的大小写

cal*_*shy 10 emacs

改变矩形的最简单方法是什么?

手册中提到的任何捷径都没有谈到这一点.我是否必须添加自定义绑定才能执行此操作?虽然我们在这里,但我如何只在矩形内搜索?

Tre*_*son 11

这是一个实现upcase-rectangle,它将大小写改为全部大写.只需替换你想要的upcasewith downcase或者capitalize任何自定义大小写转换:

(defun upcase-rectangle (b e)
  "change chars in rectangle to uppercase"
  (interactive "r")
  (apply-on-rectangle 'upcase-rectangle-line b e))

(defun upcase-rectangle-line (startcol endcol)
  (when (= (move-to-column startcol) startcol)
    (upcase-region (point)
                   (progn (move-to-column endcol 'coerce)
                          (point)))))
Run Code Online (Sandbox Code Playgroud)


san*_*inc 6

使用cua-mode矩形选择支持很容易:

(setq cua-enable-cua-keys nil)  ; enable only CUA's rectangle selections
(cua-mode t)
Run Code Online (Sandbox Code Playgroud)

然后,您可以通过按下C-RET并移动光标来选择矩形.要更新该区域,只需使用默认upcase-region绑定的常用命令M-U.

  • 是的,不是.不,因为`upcase-region`不适用于矩形,而'Mu`默认是`upcase-word`(`upcase-region`绑定到`Cx Cu`).是的,因为当选择一个矩形时,CUA将"Mu"绑定到"cua-upcase-rectangle",毫不奇怪,它可以很好地工作.您也可以使用`(cua-selection-mode t)来代替给定的代码. (4认同)
  • 感谢您的评论和澄清.但我觉得有点令人困惑(?!)有些东西这个有用的东西不能用其他rect命令开箱即用. (2认同)