Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [360]

By Root 1120 0
pressing the Control key and spacebar together (or if that doesn't work, press C-@).

Move point (the cursor) to the end of the region you want to save.

Press C-x x followed by the name of the register (a in this case).

When you want to paste the text somewhere, press C-x g followed by the name of the register, a.

Searching and Replacing

The most common way to search for a string within Emacs is to press C-s. This starts what is called an incremental search. You then start entering the characters you are looking for. Each time you press a character, Emacs searches forward for a string matching everything you've typed so far. If you make a mistake, just press the Delete key and continue typing the right characters. If the string cannot be found, Emacs beeps. If you find an occurrence but you want to keep searching for another one, press C-s again.

You can also search backward this way using the C-r key. Several other types of searches exist, including a regular expression search that you can invoke by pressing M-C-s. This lets you search for something such as jo.*n, which matches names like John, Joan, and Johann. (By default, searches are not case-sensitive.)

To replace a string, enter M-%. You are prompted for the string that is currently in the buffer, and then the one with which you want to replace it. Emacs displays each place in the buffer where the string is and asks you if you want to replace this occurrence. Press the spacebar to replace the string, the Delete key to skip this string, or a period to stop the search.

If you know you want to replace all occurrences of a string that follow your current place in the buffer, without being queried for each one, enter M-x replace-string. (The M-x key allows you to enter the name of an Emacs function and execute it, without use of a key binding. Many Emacs functions are available only via M-x, unless you bind them to keys yourself.) A regular expression can be replaced by entering M-x replace-regexp.

Macros

The name Emacs comes partly from the word macros . A macro is a simple but powerful feature that makes Emacs a pleasure to use. If you plan on doing anything frequently and repetitively, just press C-x (, perform the operation once, and then press C-x ). The two C-x commands with the opening and closing parentheses remember all the keys you pressed. Then you can execute the commands over and over again by pressing C-x e.

Here's an example you can try on any text file; it capitalizes the first word of each line.

Press C-x ( to begin the macro.

Press C-a to put point at the beginning of the current line. It's important to know where you are each time a macro executes. By pressing C-a, you are making sure the macro will always go to the beginning of the line, which is where you want to be.

Press M-c to make the first letter of the first word a capital letter.

Press C-a again to return to the beginning of the line, and C-n or the down arrow to go to the beginning of the following line. This ensures that the macro will start execution at the right place next time.

Press C-x ) to end the macro.

Press C-x e repeatedly to capitalize the following lines. Or press C-u several times, followed by C-x e. The repeated uses of C-u are prefix keys, causing the following command to execute many times. If you get to the end of the document while the macro is still executing, no harm is done; Emacs just beeps and stops executing the macro.

Running Commands and Programming Within Emacs

Emacs provides interfaces for many programs, which you can run within an Emacs buffer. For example, Emacs modes exist for reading and sending electronic mail, reading Usenet news, compiling programs, and interacting with the shell. In this section, we introduce some of these features.

To send electronic mail from within Emacs , press C-x m. This opens up a buffer that allows you to compose and send an email message (Figure 19-23).

Simply enter your message within this buffer and use C-c C-s to send it. You can also insert text from other buffers, extend the interface

Return Main Page Previous Page Next Page

®Online Book Reader