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

📄 ch16.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 5 页
字号:






</DL>







<CENTER>



<H4><A NAME="Heading38<FONT COLOR="#000077">Using Modes with Buffers</FONT></H4>



</CENTER>



<P>emacs is versatile enough to handle many 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 type 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 (if you use C-c, C-c)



after you have finished editing it.</P>



<P>emacs also supports modes for many 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 indents a line correctly based on its place



in the program (a <TT>for</TT> loop within another <TT>for</TT> loop, for example).



<CENTER>



<H4><A NAME="Heading39<FONT COLOR="#000077">Online Help in emacs</FONT></H4>



</CENTER>



<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 type 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.



<CENTER>



<H4><A NAME="Heading40<FONT COLOR="#000077">A Summary of Commands for emacs</FONT></H4>



</CENTER>



<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 list summarizes the essential commands



you need for basic editing in emacs. The emacs man page should be consulted for a



more comprehensive description of the full emacs command set. 



<TABLE BORDER="0" HEIGHT="410">



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



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



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



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">d Deletes the current character </TD>



		<TD></TD>



	</TR>



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



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



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



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">g Cancels the current command </TD>



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">h Enters emacs online help </TD>



		<TD></TD>



	</TR>



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



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



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



		<TD></TD>



	</TR>



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



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



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



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">s Searches forward for a string </TD>



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">v Scrolls forward one screen </TD>



		<TD></TD>



	</TR>



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



		<TD ALIGN="LEFT">M </TD>



		<TD ALIGN="LEFT">v Scrolls backward one screen </TD>



		<TD></TD>



	</TR>



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



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



		<TD ALIGN="LEFT">x u Undoes the last edit </TD>



		<TD></TD>



	</TR>



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



		<TD ALIGN="LEFT" VALIGN="TOP">CxCc </TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Exits emacs <BR>



					</TD>



		<TD ALIGN="LEFT"></TD>



	</TR>



</TABLE>







<TABLE BORDER="0">



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



		<TD ALIGN="LEFT">CxCs<BR>



					</TD>



		<TD ALIGN="LEFT">			<P>



		</TD>



		<TD ALIGN="LEFT">Saves the buffer to a file<BR>



					</TD>



	</TR>



</TABLE>







<CENTER>



<H3><A NAME="Heading41<FONT COLOR="#000077">The joe Editor</FONT></H3>



</CENTER>



<P>The joe editor, written by Joseph H. Allen, is very easy to use for folks who



are coming to Linux from a DOS environment. The editor's look and feel is very similar



to the old Wordstar editors, and it might be comfortable for users of the DOS edit



program. The joe editor is handy for quick edits and is powerful enough to be a decent



programmer's editor.</P>



<P>The joe editor is a shareware program that is distributed under the GNU license.



You can get the full package from ftp sites on the Internet free. The latest version



at the time of writing was version 2.2. The joe editor comes with the Slackware CD,



so you don't have to go to the Internet to get it if you can live with the next-to-latest



version. When installing Linux, you have a choice to install joe if you chose the



verbose option. If you did not choose to install joe at installation time, you can



always run the setup program again and install it later.</P>



<P>Also, don't look for a commercial version of joe. Joseph Allen clearly states



in the man pages that he is not interested in commercializing this editor. The man



pages come with more than adequate information on how to use the editor and its command-line



options.</P>



<P>The primary advantage of the joe editor is its simplicity of use. An on-screen



help menu for all the basic commands is available at any time. Type the command <TT>joe</TT>



on the command line to invoke the editor. You can type the name of one or more files



to edit by specifying them on the command line:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">$ joe filename







$ joe file1 file2 file3



</FONT></PRE>



<P>Don't let joe's easy-to-use interface fool you into believing that it's not a



powerful editor. Many features in joe make it a good, useful editor.



<CENTER>



<H4><A NAME="Heading42<FONT COLOR="#000077">A Summary of Commands for joe</FONT></H4>



</CENTER>



<P>After you are in the editor, you can type directly into the window that's presented.



Use the arrow keys to move your cursor.</P>



<P>Help is not far away if you get stuck. Type Ctrl-K, H and you are presented with



a help menu as shown in Listing 16.1. The documentation in the man pages for joe



use the notation ^K to represent pressing the Control key and the K key simultaneously.



This is the convention to follow in this section. (In the emacs editor, we would



have specified it as C-k.) It's best to stick with the same documentation style that



comes with the documents for each editor.



<CENTER>



<H3><A NAME="Heading43<FONT COLOR="#000077">Listing 16.1. Commands for the



joe editor.</FONT></H3>



</CENTER>



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



CURSOR            GO TO             BLOCK      DELETE   MISC         EXIT



^B left  ^F right ^U prev. screen   ^KB begin  ^D char  ^KJ reformat ^Ksave



^P up    ^N down  ^V next screen    ^KK end    ^Y line  ^T options   ^Cabort



^Z previous word  ^A beg. of line   ^KM move   ^W &gt;word ^R refresh   ^KZ sh



^X next word      ^E end of line    ^KC copy   ^O word&lt; ^@ insert    FILE



SEARCH            ^KU top of file   ^KW file   ^J &gt;line SPELL        ^KE edit



^KF find text     ^KV end of file   ^KY delete ^_ undo  ^[N word     ^KR insert



^L find next      ^KL to line No.   ^K/ filter ^^redo   ^[L file     ^KD save



</FONT></PRE>



<P>The commands are fairly straightforward and are not case-sensitive. For example,



copying and moving text requires the use of the block feature. Mark the start of



the block by pressing ^KB after moving the cursor to the start of the text. Then



move the cursor to the end of the text to be copied, and press ^KK. To copy the block,



press ^KC, or to delete the block press ^KY. A limited redo/undo feature can be invoked



with the ^^ and ^_ keys, respectively.</P>



<P>The editor can be customized with the use of command-line options. The listed



options include setting the baud rate for screen refresh, tabs, word wrap margins,



and which line number to start at. For example, the command</P>



<PRE><FONT COLOR="#0066FF">$ joe +23 ch16.txt



</FONT></PRE>



<P>starts the joe editor on the file <TT>ch16.txt</TT> and places the cursor on line



23 of the file.</P>



<P>Movement in the editing window is done with the arrow keys or via the commands



shown in Listing 16.1. The ^K key followed by a space character lists the current



line number.</P>



<P>The current file is saved with the ^KB command. New files can be edited with the



^KE command. You can read in the contents of another file with the ^KR command. All



commands prompt you for a filename. To abort the current edits, type ^C.</P>



<P>One of the nice features of joe includes filename completion when you press the



Tab key as the response to a command. When prompted for a filename, press the Tab



key and joe attempts to fill in the name of the file with closest name. If more than



one match exists, you hear a beep. Just press the Tab key repeatedly to have joe



list all the available choices.</P>



<P>You can type over any of the choices shown on the prompt line if you want to manually



complete the filename. To set up the joe editor as the default editor on your account,



you set your environment variables <TT>EDITOR</TT> and <TT>VISUAL</TT> to <TT>joe</TT>.



<CENTER>



<H4><A NAME="Heading44<FONT COLOR="#000077">When Should I Use joe Rather Than



vi or emacs?</FONT></H4>



</CENTER>



<P>Before you take this step and begin using joe, you should be aware of some drawbacks



of using the joe editor.</P>



<P>First of all, joe's simplicity might turn off the programmer in you. If you are



an emacs or vi hack, the joe editor might seem a little too simple to use. Choosing



a text editor is still a very personal decision.</P>



<P>Second, the use of the arrow and control keys to move around in a text file might



confuse some of the dumb dialup programs. Actually, vi is best suited for dialup



situations in which control keys cause havoc. On many occasions, I have been logged



on to computers aboard seafaring vessels using archaic means of communication and



yet have been able to use vi and not emacs! Finally, you cannot extend joe the way



you can extend emacs. No doubt, of the three editors discussed here, emacs is the



most powerful in terms of extensibility.</P>



<P>Despite these &quot;drawbacks,&quot; the joe editor has some remarkably good features.



For one thing, there is support for the use of regular expressions in joe. Also,



you can copy vertical blocks of text with the ^TX option.



<CENTER>



<H4><A NAME="Heading45<FONT COLOR="#000077">Macro Recording and Playback</FONT></H4>



</CENTER>



<P>joe also has the capability to record and play back macros. Up to 10 macros can



be recorded per session. Each macro is numbered from 0 to 9. Use the ^K[ key and



then a number from 0 to 9 to number the macro. The editor then starts recording your



keystrokes. Use ^K] to stop recording. All keystrokes typed in-between are applied



to the text in the window. To initiate playback, use ^K and then the number of the



macro you just recorded. For example, the following keystrokes record a macro to



put /* and */ around a line:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">^K[ ^A /* ^E */ ^K]



</FONT></PRE>



<P>You can use multiple windows to edit more than one file! The ^KO command opens



another window. You can have many windows open at one time. The ^KN and ^KP commands



let you traverse the next and previous windows, respectively. The ^KI command toggles



the zooming in and out of the contents of a window. Try this with vi!</P>



<P>All in all, the joe editor is a nice, simple, yet powerful editing tool for Linux.



<CENTER>



<H3><A NAME="Heading46<FONT COLOR="#000077">Summary</FONT></H3>



</CENTER>



<P>Many text editors are available for the Linux system. This chapter introduced



three of the most popular editors: vi (which is actually an alias to the elvis editor),



joe (an editor based on the old Wordstar and DOS edit editors), and emacs (the editor



for &quot;power programmers&quot;). Each text editor provides basic editing functions,



such as inserting and deleting text, reading and writing external files, text searching,



and copying and moving text. vi is a full-screen editor that has two modes: command



mode and text mode. An X Window version of vi, xvile, is available from <TT>sunsite.unc.edu</TT>



in the <TT>/pub/Linux/apps/editors/vi/vile-5.5.tar.gz</TT> file. emacs is an extendible



and powerful editor that is highly configurable to suit various editing tasks (such



as programming, document writing, and changing user or system files). An X Window



version of emacs, Xemacs, is also available from <TT>http://www.xemacs.org</TT>.



The joe editor is a full-screen editor suitable for teaching folks how to use editors,



as well as for use by programmers. To find more editors for Linux, you can look in



the <TT>/pub/Linux/apps/editors</TT> directory on <TT>sunsite.unc.edu</TT>.



















</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

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