This page shows how to {copy, cut, insert} a column of text, draw ASCII-diagram, align text.
These are most useful:
| Command | Key | Purpose |
|---|---|---|
kill-rectangle | 【Ctrl+x r k】 | Delete selected column of text. |
replace-rectangle | 【Ctrl+x r t】 | Replace text in a selected column. (This is alias to string-rectangle) |
Here's a example of how to use it.
.............. ..1xxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxx2..oooo.. ..............
set-mark-command 【Ctrl+Space】kill-rectangle| Command | Key | Purpose |
|---|---|---|
yank-rectangle | 【Ctrl+x r y】 | Paste a column of text (after you used kill-rectangle). |
The yank-rectangle is useful when you want to move a column of text. Try to swap the “x” and “o” blocks in the above sample text.
| command | Key | Purpose |
|---|---|---|
rectangle-number-lines | 【Ctrl+x r N】 | Insert numbers in a vertical column. (new in emacs 24) |
It is very useful for writing a ordered list of items. Example:
1. x 2. x 3. x 4. x
You can first make a text selection and it'll insert at the column of your cursor start position.
To start with a different number, call universal-argument 【Ctrl+u】 first.
To insert letters instead, see: Emacs Lisp: Insert Letters A to Z.
Here's other rectangle commands.
| command | Key | Purpose |
|---|---|---|
delete-rectangle | 【Ctrl+x r d】 | similar to kill-rectangle, but doesn't save to a special clipboard. |
string-insert-rectangle | ◇ | similar to string-rectangle, but doesn't replace the rectangle text. |
clear-rectangle | 【Ctrl+x r c】 | replace with space |
delete-whitespace-rectangle | ◇ | Delete all whitespace following starting corner. (this is alias to close-rectangle) |
delimit-columns-rectangle | ◇ | ◇ |
open-rectangle | 【Ctrl+x r o】 | Insert space to the rectangle. (shifting text to the right) |
If you want to copy rectangle of text to standard OS clipboard, see: Emacs Lisp: Copy Column of Text to Clipboard.
cua-mode has a nice feature that makes emacs rectangle commands much easier to use, because it highlights just the rectangle, and user can just use normal copy/paste keys to manipulate the rect.
cua-mode to turn it on.(thanks to Markus Schütz)
Emacs has several commands that's helpful for alignment. One of the most useful is align-regexp. For example, suppose you have:
tom = 5 jenny = 8 mary = 7
and you want to align them by the equal sign. Just select the text, then call align-regexp then give “=”. Then you get:
tom = 5 jenny = 8 mary = 7
Emacs also has a picture-mode, designed for drawing ASCII diagrams. I've not used it.
Open a new file. Then, call picture-mode, then call describe-mode 【F1 m】 to see how to use it.
Here's a examples of ASCII diagram you can play with.
_____________________________________________ | | | Sequence | | ______ ________________________________ | | | | | | | | | List | | Array | | | | | | ________ ________ | | | |______| | | | | | | | | | | Vector | | String | | | | | |________| |________| | | | | ____________ _____________ | | | | | | | | | | | | | Char-table | | Bool-vector | | | | | |____________| |_____________| | | | |________________________________| | |_____________________________________________|
Emacs also has artist-mode. It lets you draw ASCII pictures with mouse.
+--------------+ -----------
| +---+ | --/ ------- \--
| |+--+--------+---+ -/ --/ \-- \-
| || | | | / / ----- \ \
| || | +-----+-+ | | | ( ) | |
+-++--+--+-----+ | | \ \ ----- / /
|| | +-------+ | -\ --\ /-- /-
|+--+------------+ --\ ------- /--
| | ----------- ●●●●
| | ●●●●●●● ●●●
+---+ ●●●●● ●●●●●●●●●●● ●●●● ●●
●●●●● ●●●●●●●●●● ●●●●●● ● ● ●
●●●●● ●●●●●●●●●●●●●●●● ●● ● ● ●● ●●
●●● ●●●● ●●●● ● ● ● ●
●●● ●●●● ●●●●●● ●● ●●● ● ●●
●●● ●●● ●●● ●●●● ●●● ●● ●
● ●●● ●●●●●●● ●●●●● ●●●●●●● ●● ●
● ●● ●●● ●●● ●●●● ●●●
●● ●● ●● ●●●●● ●●● ●●●●●●●●● ●●
●● ● ● ●●●● ●●● ●● ● ●
●● ● ●● ●●● ●● ● ● ●●●●● ●●
● ● ●●●●●● ● ● ● ●● ●●
●● ●● ●● ●● ● ● ●
●●●● ● ●●● ●● ●● ●● ●
●●●●●●●● ●●●●●●●●●● ●● ●● ● ●●
●●●●●●●● ●●● ●●● ●● ●● ●
●●●●●●●● ●● ●●●●●●●●● ●●● ● ●
●●●●●●● ● ●●● ●● ●●
●●● ●● ●●● ●● ●● ●●
●●● ●●● ●● ●●●●●●●● ●●
●●●●●●●●● ●● ●● ●●●
●●● ●● ●●●●●●●●●●●●●●●●●
● ●●●●●●●●●●
● ●●●●●●●●●●●●●●●●●●●●●●
●●●● ●●●
●●●●●●●●●●●●●●●●●●●●●●●●
artist-mode.Here's video demonstrating drawing a diagram using artist-mode:
〔Emacs Screencast: Artist Mode By Seong-Kook Shin. @ http://www.cinsk.org/emacs/emacs-artist.html〕.