Corin Anderson (magellanic) wrote,
Corin Anderson

I like rectangles

Someone at work introduced me to rectangle commands in emacs. Suppose you have several lines of text, like:

A rectangle command lets you take actions on a logical rectangle of the text. For example, you could cut all the usernames out by setting the point after the first users/, setting the mark at the end of person/, and then running kill-rectangle. You can put it back with yank-rectangle. You can also add new text in, the same text on each line, with string-insert-rectangle.

I like these commands enough that I added keybindings for them. I use a Windows keyboard, which is happily endowed with some extra modifiers. The windows key is my new friend, generating the "super" modifier. I've added this to my .emacs file:

;; Operate on rectangles. Pretty fun stuff.
(global-set-key [?\s-w] 'kill-rectangle)
(global-set-key [?\s-y] 'yank-rectangle)
(global-set-key [?\s-i] 'string-insert-rectangle)

Thus, Windows-w is analogous to C-w, Windows-y to C-y, and Windows-i inserts a string.

This is just the latest installment of my unintended charge this week, of being more productive by making many little tasks more efficient. I think the hour or so spent on them will easily be paid off in the coming days and weeks.
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment