?? rhl16.htm
字號:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves the cursor to the next line.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-a
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves the cursor to the beginning of the line.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-e
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves the cursor to the end of the line.</FONT>
</TABLE><BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>When I refer to a command such as C-b, I mean press and hold the Control key while you press the letter b. The same is true for Meta commands such as M-v.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Most implementations of emacs conveniently map the first four movement commands to the arrow keys on the keyboard. Let's edit a new file called asong2. (If you are in the middle of a previous file, exit the editor by typing Ctrl-X, Ctrl-C.) Start up a
new copy of emacs by entering the following command from the shell:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">emacs asong2<Enter></FONT></PRE>
<P>Now enter the following text into the buffer:
<BR>
<PRE>
<FONT COLOR="#000080">This is a file for edit
And you have to give emacs some credit
It's really quite swell
And all you have to do is spell
emacs works, if you let it!</FONT></PRE>
<P>Now use the C-b command to move back through this horrendous piece of poetry. Notice how the cursor jumps up to the end of each line after the reaching the beginning of the previous line. This works the same way in the opposite direction using the C-f
command.
<BR>
<P>Another useful way of moving around is by scrolling through a file one screen at a time. The command C-v moves the cursor forward one screen at a time. The command M-v moves the cursor in the opposite direction.
<BR>
<P>Like vi, emacs treats a sequence of non-whitespace characters as a word. You can move the cursor forward one word at a time with the M-f command. The M-b command moves back one word.
<BR>
<BR>
<A NAME="E69E227"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Quitting emacs</B></FONT></CENTER></H4>
<BR>
<P>At this time, you can stop editing to save the contents of the buffer to your file asong2. To do this, issue the command sequence C-x C-s. As you enter this command, notice how the command is displayed on the echo line as you type it. To quit emacs and
return to the shell, enter the command C-x C-c. If you have made changes that haven't been saved using C-x C-s, emacs will ask for confirmation before quitting.
<BR>
<BR>
<A NAME="E69E228"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Deleting Text</B></FONT></CENTER></H4>
<BR>
<P>You can delete text in several ways. The Backspace (or Delete) key is used to erase the character immediately preceding the cursor. The command C-d deletes the character underneath the cursor, and C-k deletes or "kills" all characters from the
cursor to the end of the line. Words can be deleted also: M-d deletes the word the cursor is currently located over and M-Del (the Delete key) deletes the word previous to the current word.
<BR>
<P>If you ever find that you have committed an edit that you didn't really want, just type C-x u to undo the previous editing changes. You can repeat the undo command as many times as you want, rolling over all the changes you made. This is an advantage
over vi, which can only undo the last change.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Change your mind about a command? Type C-g to abort the current command operation.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E229"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Working with Multiple Files</B></FONT></CENTER></H4>
<BR>
<P>emacs enables you to edit several files in one session, each contained within its own buffer. To copy an external file into a new buffer, use the C-x C-f command. After entering this command, you will see the following prompt on the echo line:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">Find file: ~/</FONT></PRE>
<P>emacs is smart when it looks for files. It supports filename completion, which means that you can simply type a few characters of a filename and emacs will attempt to match a file (or files) to what you have typed so far. To do this, type in the letters
".log" and press the Tab key. emacs expands this to ~/.login (or any other filename that matches). If two or more files match the pattern supplied, pressing the Tab key will cycle through them.
<BR>
<P>After you have loaded a new file into emacs, you can switch between buffers by using the C-x b command followed by the name of the buffer that you want. The buffer's name is that of the file that was loaded into it. The C-x b command also uses filename
completion, so you can use the Tab key to cycle through your edit buffers after supplying a few relevant characters.
<BR>
<P>When you have finished editing a buffer, instead of saving the contents using the C-x C-s command, you may decide that you do not really want to keep the edits you have made. You can "kill" the current buffer by entering the command C-x k.
emacs will prompt you for the name of the buffer to kill, but you can kill the current buffer by simply pressing Return. emacs will ask for confirmation, to which you can respond by typing yes (if you're sure) and press Return.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Whenever you are working with just two buffers, you can simply press Return after entering the C-x b command to switch to the other buffer.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E230"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Copying and Moving Text</B></FONT></CENTER></H4>
<BR>
<P>In order to copy and move blocks of text in emacs, you must define the region of text by marking the beginning and end points of the text block. This is done by moving the cursor to where you want the block to begin and marking it using the C-Space
command (in this case, Space means literally the spacebar). The end of the block is defined by wherever you place the cursor after that. To make a copy of the block, enter the command M-w. The text within the block is copied to emacs's internal clipboard,
from which it can be pasted at another location using the C-y command. Alternatively, you can cut the block into the clipboard using C-w instead of M-w. Cutting, of course, deletes the text from its current location.
<BR>
<P>Let's try out some of these techniques on your buffer asong2. Use the M-< command to jump to the beginning of the buffer. Enter a C-Space to mark the start of the block and then use C-n to move down a line. Cut the block to the clipboard using C-w,
move the cursor to the end of the buffer using M->, and paste it using C-y. The result should look like this:
<BR>
<PRE>
<FONT COLOR="#000080">It's really quite swell
And all you have to do is spell
emacs works, if you let it!
This is a file for edit
And you have to give emacs some credit</FONT></PRE>
<BR>
<A NAME="E69E231"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Searching and Replacing Text</B></FONT></CENTER></H4>
<BR>
<P>You can search forward and backward through text using the C-s and C-r commands, respectively. These commands, like many in emacs, use command completion. This is the same concept as filename completion: you supply a few characters and emacs tries to
fill in the rest. In this case, however, emacs moves the cursor to each instance it finds of the string supplied.
<BR>
<P>As you enter more characters, emacs narrows its search further. When you have found a correct match, press Return or use any of the cursor-movement commands to halt the search.
<BR>
<P>As with vi, searching in either direction wraps around the beginning or end of the file, depending on in which direction you are searching. However, when emacs reaches the top or bottom of the file, it will tell you that the search failed. You can keep
searching by pressing C-s or C-r accordingly and emacs will continue using the current string.
<BR>
<P>To illustrate how searching in emacs works, let's search backward through your file asong2. Enter C-r and type an s. emacs moves the cursor to the "s" in "works". Now type a w. emacs now tries to find a pattern that matches the
string sw. The cursor ends up on the "w" in "swell". You can edit the search string using the Backspace or Delete key. Delete the w and type a p. What happens?
<BR>
<P>Search-and-replaces are done by entering the query-replace command. This is qualified by the M-x command, which tells emacs that the text to follow is a full command and not a key combination. After you have entered the query-replace command, you will
be prompted for the string to be found. Enter the string and press Return. emacs will then prompt you for the replacement string. Once you have entered the replacement string, emacs will search for every instance of the first string and, if it finds one,
asks you if it should be replaced with the second string.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>emacs is actually composed of a set of explicit command names that are bound to key combinations. The query-replace command is bound to M-% in some implementations of emacs.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E232"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Using Modes with Buffers</B></FONT></CENTER></H4>
<BR>
<P>emacs is versatile enough to handle many different types of editing chores. It enables you to associate modes to buffers so that you can have text formatting specific to your editing application. If you enter the command C-x m, emacs enters mail mode,
which formats a buffer with To: and Subject: fields as well as a space for the body of the mail message. emacs can even send the mail message for you (by entering C-c C-c) after you have finished editing it.
<BR>
<P>emacs also supports modes for many different programming languages such as C. When a file with the extension .c (C source code) or .h (C header file) is loaded into emacs, the buffer is automatically set to C mode. This mode has knowledge of how C
programs are formatted, and pressing the Tab key will indent a line correctly based on its place in the program (a for loop within another for loop, as an example).
<BR>
<BR>
<A NAME="E69E233"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Online Help in emacs</B></FONT></CENTER></H4>
<BR>
<P>One of the best features of the emacs editor is that if you ever get stuck, or are just plain overwhelmed by it all, help is just a few keystrokes away—and lots of it! If you need a short emacs tutorial, just enter C-h t. If you would like to find
out what function a particular key supports, type C-h k and then press the key. The help option has many different topics. Use C-h i to load the information documentation reader and read about all the types of help available.
<BR>
<BR>
<A NAME="E69E234"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>A Summary of Commands</B></FONT></CENTER></H4>
<BR>
<P>emacs, like the vi editor, has such a rich command set that we can cover only a portion of it in this chapter. The following table is a summary of the strictly essential commands that you will need for basic editing in emacs. The emacs man page should
be consulted for a more comprehensive description of the full emacs command set.
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-b
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves back one character.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-d
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Deletes the current character.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-f
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves forward one character.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-g
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Cancels the current command.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-h
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Enters emacs online help.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-n
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves forward to the next line.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-p
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Moves back to the previous line.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-s
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Searches forward for a string.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-v
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Scrolls forward one screen.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
M-v
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Scrolls backward one screen.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-x u
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Undoes the last edit.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-x C-c
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Exits emacs.</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
C-x C-s
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Saves the buffer to a file.</FONT>
</TABLE><BR>
<A NAME="E68E118"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>
<BR>
<P>There are many text editors available for the Linux system. Two of the most popular are vi (which is actually an alias to the elvis editor) and emacs. Both provide basic editing functions such as inserting and deleting text, reading and writing of
external files, text searching, <A NAME="I2"></A>and copying and moving text. vi is a full-screen editor that has two modes: command mode and text mode. emacs is an extendible and powerful editor that is highly configurable to suit a variety of editing
tasks (such as programming, document writing, and changing user or system files).
<P ALIGN=LEFT>
<A HREF="tppmsgs/msgs0.htm#16" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl15.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl17.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl17.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
</BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -