-->
Previous Table of Contents Next


When emacs finds an occurrence of Linux, it stops and prompts for an action. The possible responses are as follows:

Keystroke Action
<Ctrl-g> Cancels operation
<!> Replaces the rest without prompting
<?> Gets a list of options
<.> Replaces the current instance and quits
<,> Replaces current instance but doesn’t move on to next instance
<y> or Spacebar Replaces and continues with replace operation
<n> Doesn’t replace but continues with replace operation

Changing Text

Another editing task you’re often faced with is changing text or replacing one text string with another (there isn’t too much difference between the two operations). You use the replace commands to replace a single character or sequence of characters. You can also use the change commands to fix one of the most common typing mistakes made—transposing two letters. Table 28.3 summarizes the change commands.

Table 28.3 Change Commands

Keystroke Action

<Ctrl-t> Transposes two adjacent letters
<Esc><t> Transposes two words
<Ctrl-x><Ctrl-t> Transposes two lines
<Esc><c> Properly capitalizes the word (initial capitalization)
<Esc><l> Lowercases the entire word
<Esc><u> Uppercases the entire word

The changes take place relative to the position of the cursor. Position the cursor at the location in the buffer file you want to correct before using these commands.

Copying, Cutting, and Pasting

When you delete or cut characters, words, lines, or a portion of a line, the deleted object is saved in what’s called the kill buffer. The name isn’t too important; what’s important is that you can put or paste the contents of the kill buffer anywhere in the text you’re editing. You do that with <Ctrl-y>, the yank command. <Ctrl-y> pastes the object to the right of or after the cursor position.

Here is an example showing the use of <Ctrl-y> to paste the contents of the kill buffer after the cursor:

Before:


Carefully carry these out instructions.

Delete the word “out” and a space by pressing <Esc-d>. Now move the cursor to the space after the y in “carry” and press <Ctrl-y>.

After:


Carefully carry out these instructions.

To copy a sequence of four lines to another portion of the text, you must first mark the four lines of text, delete them to the kill buffer, and then yank them back at the appropriate places. Follow these steps:

1.  Position the cursor at the beginning of the first of the four lines.
2.  Press <Ctrl-Spacebar> to set the mark.
3.  Move the cursor to the end of the fourth line. This creates what emacs refers to as a region.
4.  Delete the text by pressing <Ctrl-w>.
5.  Because you want to copy the lines, you must replace the deleted text. Do this with the <Ctrl-y> command.
6.  Move the cursor to the point in the buffer where you want to copy the text.
7.  Press <Ctrl-y> to paste the yanked lines below the line holding the cursor.


TROUBLESHOOTING:  
I deleted the marked region, but the region I marked wasn’t deleted. Unfortunately, GNU emacs supplied with Linux doesn’t display any type of marker to indicate the mark, so it’s very easy to forget to set the mark or to place it in an inappropriate position. To check the position of the mark, use the command <Ctrl-x><Ctrl-x>. This command swaps the position of the cursor and the mark. If the cursor moves to the position where you thought the mark was located, you know the mark is properly set. To move the cursor back to the proper position, simply reissue <Ctrl-x><Ctrl-x> to swap them back.


Previous Table of Contents Next