Working With Rectangles

Xah Lee has a nice updated post on working with rectangles and some other loosely related matters. Every time I see these commands I think how useful they are and then promptly forget about them. I'm going to make an effort to try to use them more often to set them in my mind.

I especially like the replace-rectangle and string-insert-rectangle commands that let you replace the rectangle or add text to the beginning of each line of the rectangle. A sometimes useful related command is kill-rectangle that just deletes the rectangle (and puts it in the kill ring).

Lee also presents a bit of Elisp that shows how to copy a rectangle into the system's clipboard. I like this not because it's something I want to do but because of the techniques he uses to copy the rectangle into the kill buffer. It's something that looks like it could be useful in other contexts.


replace-rectange Ctrl+x r t
string-insert-rectangle Unbound
kill-rectangle Ctrl+x r k
This entry was posted in General and tagged . Bookmark the permalink.
  • Phil

    For convenience, I bind the following to C-x r M-w

    (defun my-copy-rectangle (start end &optional fill)
    "Trigger the read-only behaviour of `kill-rectangle'."
    (interactive "r\nP")
    (let ((buffer-read-only t)
    (kill-read-only-ok t))
    (kill-rectangle start end fill)))