UNIX For Dummies [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

UNIX For Dummies [Electronic resources] - نسخه متنی

John Levine, Margaret Levine Young

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






A Novel Concept in Editing: emacs Makes Sense

We don’t want to get your hopes up, but emacs is much easier to use than vi . The reason is that it doesn’t have the mysterious modes that require you to remember at every moment whether the program is expecting a command or text.
On the other hand, commands in emacs aren’t exactly intuitive. Still, we like them better. In case you are wondering, the name emacs comes from editor macros because the original version of emacs was written as an extension to an early text editor called teco , an editor that makes ed (see the section "Talk to Mr.

ed ," at the end of this chapter) look like the winner of the Nobel prize for user-friendliness. (Scary thought, isn’t it?) To run emacs , type this line:


emacs eating.peas

You replace eating.peas with the name of the file you want, of course. If the file you name doesn’t exist, emacs creates it. Like vi , emacs displays a full-screen view of your file, as shown in Figure 10-2. On the bottom line of the screen is the status line, which tells you the name of the file you are editing and other, less interesting information.


Figure 10-2: The GNU Emacs display in a text console. At the bottom of the screen, emacs displays in the status line the filename and other mysterious information.


A tale of two emacs


Unlike vi , emacs does not automatically come with UNIX. Because most versions of emacs are distributed for free, however, most systems have it or can get it. By far the two most common versions of emacs are GNU Emacs and XEmacs. Despite the name, XEmacs runs under both X Windows and text-based consoles, and so does GNU Emacs. The basic commands are the same for both versions, and the most obvious differences between the two are the button bars and more sophisticated 3-D look to the windows in XEmacs. (Compare the difference in Figures 10-3 and 10-4.) Other than that, it really doesn’t matter which you use.

Figure 10-3: The GNU Emacs display in an X windowincludes pull-down menus for most common commands, includig save, search, undo, and help.


Figure 10-4: The XEmacs display in an X window includes a toolbar in addition to pull-down menus and a 3-D look to the interface.









Tip More than just a text editor


The emacs program is a cornucopia of bells and whistles, including two different e-mail packages, a newsreader, a file manager, color text highlighting, and countless other fun and unnecessary features. These features make emacs a much larger package than any other editor (it has been somewhat accurately called an operating system disguised as an editor) and has been known to cause some system administrators to balk at installing it on their UNIX machines. For others, it’s almost a way of life, so whether you have access to emacs may depend on how strongly your system administrator feels about those types of things.



If you get an error message when you try to run emacs , ask your system administrator what’s up. The emacs program may have another name on your system. If your system administrator says that you don’t have emacs , plead with him or her to get it.



If emacs looks or acts weird (weirder than usual, that is), your terminal type may not be set correctly. Again, ask your system administrator to straighten it out.













Tip To run XEmacs on the eating.peas file, type the command xemacs eating. peas.


Telling emacs what to do


Rather than have two modes, as does vi , emacs treats normal letters, numbers, and punctuation as text and sticks them in your file when you type them. (Pretty advanced concept, huh?) Commands are usually given by pressing combinations of the Ctrl (Control) key and a letter. You also give some commands by pressing the Meta key and a letter.

Tip On most computers, the Meta key is the Esc key. If your keyboard has an Alt key, it may be the Meta key. Try Alt to see whether it works. If it doesn’t, use Esc. Unlike with Alt, if you use Esc you must release the Esc key before you type the subsequent letter (Esc, release, letter). In the following section, we tell you to press Esc.


Another novel concept: Type to enter text


To enter text, just start typing! The text is inserted wherever your cursor is.


Getting around in emacs


To move the cursor around in your text, use these keys:



Arrow keys usually move the cursor up, down, left, and right.

Tip In a few situations, emacs doesn’t understand the arrow keys. If that’s true for you, press Ctrl+B to move backward one character, Ctrl+F to move forward one character, Ctrl+P to move to the preceding line, and Ctrl+N to move to the next line. At least they tried to make them mnemonic.



Ctrl+A moves to the beginning of the line.



Ctrl+E moves to the end of the line.



Esc+< (press Esc and then hold down Shift and press the comma key) moves to the beginning of the file.



Esc+> (press Esc and then hold down Shift and press the period key) moves to the end of the file.




Making changes in emacs


Even though emacs is a better text editor, you still make typos, change your mind, and think of brilliant improvements to your text. To change text, follow these steps:



Move the cursor to the beginning of the text you want to change.


Type the new text. The text is inserted wherever the cursor is.


Delete any text you don’t want.


It’s that simple. No weird commands required.









Tip Emergency exit from emacs


To stop using emacs , press Ctrl+X followed by Ctrl+C.

This command doesn’t save any changes you made to the file in emacs . It just gets you out. Some versions of emacs may ask whether you want to save the file the editor was looking at or say something like "Buffers not saved. Exit?" (Translation: "Do you really want to quit without saving your changes?") Press Y for yes or N for no, as appropriate. If you just want to get out, press N to the "Do you want to save" question or Y to the "Buffers not saved" question.



















Tip Moving text in emacs


Although this subject is beyond the scope of this quick introduction to emacs , we tell you how to move text from one place to another in a file. It turns out that when you press Ctrl+K to kill the text from the cursor to the end of the line, the killed information is stored in a temporary place called the kill buffer. You can copy the information from the kill buffer back into your file by pressing Ctrl+Y (yank it back into the file). To move some text, kill it with Ctrl+K, move the cursor to the new location, and press Ctrl+Y to insert the text where your cursor is. (Kill and yank in emacs -ese correspond to cut and paste in the regular world.) If emacs is running in an X window, the kill buffer is connected to X’s cut-and-paste system, which means that you can cut and paste between emacs and other programs.












Deleting stuff in emacs


emacs has several commands for deleting stuff:



To delete the character the cursor is on, press Ctrl+D. Or, on many terminals, press the Del key.



To delete text from the cursor to the end of the word (up to a space or punctuation mark), press Esc and then D.



To delete from the cursor to the end of the line, press Ctrl+K.




Save that file before it’s too late!


To save the text in the file, press Ctrl+XS (press and hold down the Ctrl key, press X and S, and then release the Ctrl key). You should save your work every few minutes. Even though emacs isn’t as frustrating as vi (or ed , for that matter), lots can still go wrong.


Bidding emacs adieu


When you finish editing and want to leave emacs , press Ctrl+XC (press and hold down the Ctrl key, press X and C, and then release the Ctrl key). You leave emacs and see the UNIX shell prompt.
If you didn’t save your work, emacs politely points out that your buffers stuff you have been working on) aren’t saved and asks whether you really want to exit. It suggests pressing the n key as the safe default in case you want to return to emacs to save the file. To leave without saving, press the y key and then Enter.

It takes many fewer emacs commands to make a file and type some stuff, make a few changes, and then save the file and leave than it does with ed or vi . The emacs program has tons of commands, most of which are utterly useless. Table 10-2 lists the commonly used emacs commands.



















































Table 10-2: Commands in emacs

Command

Description

Ctrl+A

Move to the beginning of the line

Ctrl+B

Move back one space

Ctrl+D

Delete one character

Ctrl+E

Move to the end of the line

Ctrl+F

Move forward one space

Ctrl+K

Delete to the end of the line

Ctrl+N

Move to the next line

Ctrl+P

Move to the preceding line

Ctrl+XC

Leave emacs

Ctrl+XS

Save the file

Esc+<


Move to the beginning of the file

Esc+>


Move to the end of the file

Esc+D

Delete to the end of the word


/ 213