What would be simplest way to change the case of a rectangle?
None of the short-cuts mentioned in the manual talk about this. Do I have to add a custom binding to do that? And while we are at it, how do I search only within a rectangle?
It's easy with using cua-mode
's rectangle selection support:
(setq cua-enable-cua-keys nil) ; enable only CUA's rectangle selections
(cua-mode t)
You can then select rectangles by pressing C-RET and moving the cursor. To upcase that region, just use the usual upcase-region
command, bound to M-U by default.
Here's an implementation of upcase-rectangle
, which changes the case to all uppercase. Just replace the upcase
with downcase
or capitalize
or whatever custom case transformation you want:
(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)))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With