Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have this text:


and want this one:


I would like to be able to write ABCDE and somehow `transpose' it and kill-yank it as a rectangle.

Can this be done without too much lisp hacking?

share|improve this question
up vote 2 down vote accepted
(defun insert-column (chars)
  (interactive "sChars to enter: ")
  (insert-rectangle (mapcar 'string (string-to-list chars))))
share|improve this answer
This is good, tanks. It would be even better if one could do it for several lines together (like rectangles). – Alfred M. May 11 '12 at 9:57
You mean more than just one character per line? That's just a matter of splitting the input string differently. (But then you might as well just got with the plain rectangle operations...) – Eli Barzilay May 11 '12 at 13:32
I mean being able to kill a region in a special way and yank it in columns. But the code you provided is already pretty useful. – Alfred M. May 21 '12 at 6:22
Well, for that you have the usual rectangle commands -- in this case, C-x r k to kill a rectangular region, and C-x r y to paste it elsewhere. – Eli Barzilay May 22 '12 at 2:00
I meant something similar to this usual command but with transposition. – Alfred M. May 22 '12 at 5:52

Mark relevant text. Then press:

M-x delete-trailing-whitespace

Place cursor at beginning. Type the following (with returns at the relevant places)

M-x map-query-replace-regexp



This procedure cleans first the trailing whitespace per line, then, per line end inserts A, B, etc. one by one at these end of lines. Other replacement patterns, are, of course, possible. It is not strictly a rectangle transpose, but quite versatile and is typically closer to what one wishes, as replacements are not necessarily in the same column, but rather determined by pattern.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .