⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch16.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<P>If you start emacs with a file, the screen displays the contents starting from



the first line. Note the two lines at the bottom of the screen. The first of these



lines, known as the mode line, displays the name of the file being edited and which



part of the file you are looking at (for example, <TT>TOP, 20%, BOT</TT>). The last



line on the screen is the echo line, which emacs uses to display system messages



and to prompt for more input.



<CENTER>



<H4><A NAME="Heading26<FONT COLOR="#000077">Control and Meta Keys</FONT></H4>



</CENTER>



<P>You are quite free at this point to start entering text into the edit buffer at



the cursor location. However, you're probably wondering, &quot;How do I move the



cursor around?&quot; Before I fill you in on this little detail, you should know



something about two keys: the Control key (which I will refer to as C) and the Meta



key (denoted by M). The Control key is used in most of the commands for emacs, but



some use the Meta key instead. Commands in emacs consist of combinations of the Control



or Meta key followed by some other character. It is necessary to hold down the Control



key when pressing the next character, whereas the Meta key can be pressed and released



before you enter the next character. For the PC, the Meta key is usually the Alt



key.







<DL>



	<DT></DT>



</DL>







<CENTER>



<H3><A NAME="Heading27<FONT COLOR="#000077">NOTE</FONT></H3>



</CENTER>











<BLOCKQUOTE>



	<P>You'll see the Control key abbreviated as C and the Alt key denoted by M.







</BLOCKQUOTE>







<CENTER>



<H4><A NAME="Heading28<FONT COLOR="#000077">Moving the Cursor</FONT></H4>



</CENTER>



<P>Now that you know about the Control key, we can talk about the cursor-movement



commands. Following are the basic ones you need to remember: 



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C </TD>



		<TD ALIGN="LEFT">f Moves the cursor forward one character </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C </TD>



		<TD ALIGN="LEFT">b Moves the cursor back one character </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C </TD>



		<TD ALIGN="LEFT">p Moves the cursor to the preceding line </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C </TD>



		<TD ALIGN="LEFT">n Moves the cursor to the next line </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C </TD>



		<TD ALIGN="LEFT">a Moves the cursor to the beginning of the line </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="66" ALIGN="LEFT">C<BR>



					</TD>



		<TD ALIGN="LEFT">e Moves the cursor to the end of the line<BR>



					</TD>



	</TR>



</TABLE>











<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading29<FONT COLOR="#000077"><B>NOTE: </B></FONT>When I refer to



	a command such as C-b, I mean that you press and hold down the Control key while



	you press the letter b. The same is true for Meta commands such as M-v.



<HR>







</DL>







<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 <TT>asong2</TT>.



(If you are in the middle of a previous file, exit the editor by pressing Ctrl-X,



Ctrl-C.) Start a new copy of emacs by entering the following command from the shell:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">emacs asong2



</FONT></PRE>



<P>Now enter the following text into the buffer:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 only 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 the preceding line after reaching the



beginning of the lower line. This works the same way in the opposite direction using



the C-f command.</P>



<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.</P>



<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 the cursor back one word.



<CENTER>



<H4><A NAME="Heading30<FONT COLOR="#000077">Quitting emacs</FONT></H4>



</CENTER>



<P>At this time, you can stop editing to save the contents of the buffer to your



file <TT>asong2</TT>. 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 asks for confirmation before



quitting.



<CENTER>



<H4><A NAME="Heading31<FONT COLOR="#000077">Deleting Text</FONT></H4>



</CENTER>



<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 &quot;kills&quot; 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-Delete (the Delete key) deletes



the word preceding the current word.</P>



<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 preceding 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 undo only the last change.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading32<FONT COLOR="#000077"><B>TIP: </B></FONT>Change your mind



	about a command? Type C-g to abort the current command operation.



<HR>







</DL>







<CENTER>



<H4><A NAME="Heading33<FONT COLOR="#000077">Working with Multiple Files</FONT></H4>



</CENTER>



<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 see the following prompt on the echo line:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 attempts



to match a file (or files) to what you have typed so far. To do this, type the letters



<TT>.log</TT> and press the Tab key. emacs expands this to <TT>~/.login</TT> (or



any other filename that matches). If two or more files match the pattern supplied,



a press of the Tab key cycles through them.</P>



<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 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.</P>



<P>When you have finished editing a buffer, instead of saving the contents using



the C-x, C-s command, you might decide you don't really want to keep the edits you



have made. You can &quot;kill&quot; the current buffer by entering the command C-x,



k. emacs prompts you for the name of the buffer to kill, but you can kill the current



buffer by simply pressing Enter. emacs asks for confirmation, to which you can respond



by typing <TT>yes</TT> (if you're sure) and pressing Enter.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading34<FONT COLOR="#000077"><B>TIP: </B></FONT>Whenever you are



	working with just two buffers, you can simply press Enter after entering the C-x,



	b command to switch to the other buffer.



<HR>







</DL>







<CENTER>



<H4><A NAME="Heading35<FONT COLOR="#000077">Copying and Moving Text</FONT></H4>



</CENTER>



<P>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. You carry out this task 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 you can paste it at another location with the C-y command. Alternatively,



you can cut the block into the clipboard using C-w rather than M-w. Cutting, of course,



deletes the text from its current location.</P>



<P>Let's try out some of these techniques on your buffer <TT>asong2</TT>. Use the



M-&lt; command to jump to the beginning of the buffer. Use 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-&gt;, and paste it using



C-y. The result should look like this:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">It's really quite swell



And all you have to do is spell



emacs works, if only you let it!



This is a file for edit



And you have to give emacs some credit



</FONT></PRE>



<CENTER>



<H4><A NAME="Heading36<FONT COLOR="#000077">Searching and Replacing Text</FONT></H4>



</CENTER>



<P>You can search forward through text by using the C-s command and backward through



text by using C-r. 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.</P>



<P>As you enter more characters, emacs narrows its search further. When you have



found a correct match, press Enter or use any of the cursor-movement commands to



halt the search.</P>



<P>As with vi, searching in either direction wraps around the beginning or end of



the file, depending on which direction you are searching in. When emacs reaches the



top or bottom of the file, however, it tells you that the search failed. You can



keep searching by pressing C-s or C-r accordingly, and emacs continues using the



current string.</P>



<P>To illustrate how searching in emacs works, let's search backward through your



file <TT>asong2</TT>. Type C-r and press <TT>s</TT>. emacs moves the cursor to the



&quot;s&quot; in &quot;works.&quot; Now press <TT>w</TT>. emacs now tries to find



a pattern that matches the string <TT>sw</TT>. The cursor ends up on the &quot;<TT>w</TT>&quot;



in &quot;swell.&quot; You can edit the search string using the Backspace or Delete



key. Delete the <TT>w</TT> and press <TT>p</TT>. What happens?</P>



<P>To perform search-and-replaces, you enter 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 are



prompted for the string to be found. Enter the string and press Enter. emacs then



prompts you for the replacement string. After you have entered the replacement string,



emacs searches for every instance of the first string and, if it finds one, asks



you whether the first string should be replaced with the second string.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading37<FONT COLOR="#000077"><B>NOTE: </B></FONT>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.



<HR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -