Sams Teach Yourself Emacs in 24 Hours |
||||||||||||||||||||||
Hour 4: Basic Editing |
||||||||||||||||||||||
|
A capability that makes a computer better than an ordinary typewriter is cut-and-paste, which is the capability to move text around in your documents, copy text into several places, and so on.
To mark a region you want to cut or copy, you can use either the mouse or the keyboard.
This task shows you how to mark a region using the mouse and copy this region to the clipboard (called kill-ring in Emacs). Follow these steps:
1. Place the mouse over the start of the text you want to mark.
2. Click the left mouse button and, while you keep the mouse button down, drag to the location where the selection should end.
4. If you want to copy the text to the clipboard (that is, don't delete it from the buffer), select the Edit menu, and chose Copy. If, on the other hand, you want to cut the text to the clipboard (that is, delete it from the buffer), go to the Edit menu and select Cut.
If you need to copy the text, it is not necessary in GNU Emacs to select the copy entry from the menu.
This task shows you how to mark a region using the keyboard and copy this region to the clipboard (called kill-ring in Emacs).
2. Press Ctrl+Spacebar. Below the buffer, the text Mark set should appear.
4. If you want to copy the text to the clipboard, press M-w (kill-ring-save); otherwise press C-w (kill-region) to cut the text to the clipboard.
It is often useful to mark the region using the mouse and then cut or copy using the keyboard. That is, use steps 1-3 from the previous task and step 4 from this task.
Although it might seem difficult to remember the keybindings, you should try to do so. They make your interaction with Emacs much faster, for example, if you do not need to use the mouse when you use cut-and-paste.
You can paste using either the mouse or the keyboard. To paste using the mouse simply press the middle mouse button at the location where you want to insert the text. To paste using the keyboard, place point at the location where you want the text to be inserted and press C-y (yank).
Emacs saves not only the latest selection made but several of them. This makes it possible to paste an old selection into the buffer. To paste an old selection, press C-y (yank), which pastes the latest selection made into the buffer. Next, press M-y (yank-pop), which replaces the inserted text with the second-to-last selection. Subsequent M-y's replace the text with even older selections.
The following steps show you how to paste an earlier selection into the buffer as described previously.
1. Before I created Figure 4.7 I cut the text One, Two, and Three in that order (that is, Three is the latest selection, Two is the previous, and One is the first). The initial content of the buffer is shown in Figure 4.7.
2. Now press C-y (yank). This inserts the latest selection (see Figure 4.8).
3. Press M-y once to replace the pasted text with the second-to-last selection (see Figure 4.9).
4. Pressing M-y once again replaces the pasted text again, this time with the third-to-last selection (see Figure 4.10).
If you press any other key between C-y and any of the M-y's then you are stuck with the given selection. That is, you won't be able to press M-y to get to older selections.
If you are using GNU Emacs you might also find the older selections in the menu bar. They are located in the Edit menu, under the submenu Select and Paste. Please note that this is not available in XEmacs.
Apart from the command bound to C-w (kill-region), other commands delete text from the buffer and copy it to the clipboard. The most useful of these is C-k (kill-line), which removes from point to the end of the line and inserts it on the clipboard. You can press it several times to remove several lines and append them to the text on the clipboard. That is, when you paste the text, all the lines are pasted as one entity.
Remember from earlier in the hour that C-d deletes the next character. Likewise the Delete key deletes the previous character. Two other very useful commands cut text-- M-d (kill-word) deletes the next word and M-DEL (backward-kill-word) kills the previous word. Both these commands cut text to the clipboard.
An other way to insert some text into your document is to simply insert a whole file. You can do that by pressing C-x i (insert-file).
Sams Teach Yourself Emacs in 24 Hours |
||||||||||||||||||||||
Hour 4: Basic Editing |
||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.