Don't understand german? Read or subscribe to my english-only feed.

mika’s advent calendar – day 2: working with rectangles in Emacs and Vim

Emacs provides functions for working with rectangles. You just have to set the mark at one point of the rectangle (either C-Space or left click), go to another point of the rectangle (or right click) and then execute a rectangle function/command, like:

C-x r k         Kill the text of the region-rectangle (kill-rectangle)
C-x r y         Yank the last killed rectangle with its upper left corner at point (yank-rectangle)
C-x r t string  Replace rectangle contents with string on each line (string-rectangle)

Execute ‘C-h a rectangle’ for builtin help or check out the rectangles part of the emacs documentation for further details.

In Vim you work with rectangles using the visual block mode. Enter the visual block mode (hit ctrl-v) and mark the columns you want to modify moving around with the cursor. Then use the normal commands/keybindings like y for yanking, p for pasting, x for deleting,… for editing. Check out ‘:help visual.txt’ for further information.

No matter whether you prefer Emacs or Vim, but know how to work with rectangles within $EDITOR.

Comments are closed.