I’ve read in several places that the rectangle functions in emacs are very useful. I’ve read a bit about them, and I can’t quite figure why. I mean, when you want to kill a paragraph, you mark the first row/column and then the last one, and that’s actually a rectangle, right? But you can still use the normal kill…
So what kind of transformations would you do with them?
If you have data in columns in a text file with
M-x delete-rectangleorM-x kill-rectangleyou can delete a single column of data. Similarly,M-x yank-rectanglewill paste in a column of text.For example, take the following text:
Select from the a of alligator to the g of guitar. The beginning and end of the selection mark out two opposite corners of the rectangle. Enter
M-x kill-rectangleand you immediately have:Next put the mark at the end of the top line, add a few spaces if required and enter
M-x yank-rectangleand ta-da! You have re-ordered the columns: