299-304.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 108 行

HTML
108
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Text Editors: vi and emacs</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=16//-->

<!--PAGES=299-304//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch15/295-298.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="304-307.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2 ALIGN="CENTER"><FONT COLOR="#000077"><I>Part III<BR>Editing, Typesetting, and More

</I></FONT></H2>

<DL>

<DT><B>In This Part</B>

<DT>&#149;&nbsp;&nbsp; Text Editors: vi and emacs

<DT>&#149;&nbsp;&nbsp; groff

<DT>&#149;&nbsp;&nbsp; geqn and gtbl

<DT>&#149;&nbsp;&nbsp; TeX and LaTeX

<DT>&#149;&nbsp;&nbsp; Printing

<DT>&#149;&nbsp;&nbsp; Multimedia Linux

</DL>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 16<BR>Text Editors: vi and emacs

</FONT></H2>

<P><I>by Peter MacKinnon</I></P>

<DL>

<DT><B>In This Chapter</B>

<DT>&#149;&nbsp;&nbsp; What are editors and why do I need one?

<DT>&#149;&nbsp;&nbsp; The editing functions

<DT>&#149;&nbsp;&nbsp; The vi editor

<DT>&#149;&nbsp;&nbsp; The emacs editor

</DL>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">What Are Editors and Why Do I Need One?</FONT></H3>

<P>A <I>text editor</I> is one of the most essential tools provided with the Linux (or virtually any) operating system. With an editor, you can create and modify text files that have a wide variety of applications:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;User files such as <TT>.login</TT> and <TT>.cshrc</TT>

<DD><B>&#149;</B>&nbsp;&nbsp;System files

<DD><B>&#149;</B>&nbsp;&nbsp;Shell programs

<DD><B>&#149;</B>&nbsp;&nbsp;Documents

<DD><B>&#149;</B>&nbsp;&nbsp;Mail messages

</DL>

<P>These are but a few of the many different types of text files that you will use when working with Linux. Basically, editors enable you to insert, delete, move, and search text ranging from individual characters to thousands of lines.

</P>

<P>Two of the most popular editors for the Linux system are <TT>emacs</TT> and <TT>vi</TT>. These editors are both full-screen text editors; put simply, they use every row and column of your terminal screen to display the textual contents of a file. Both of these editors feature a rich set of commands. The essential commands for manipulating text can be learned reasonably quickly; the more sophisticated commands may take a little longer to master. However, you will likely appreciate this investment as you see how much time these powerful tools can save you.</P>

<P>Choosing one editor over another can be a matter of taste. Both <TT>emacs</TT> and <TT>vi</TT> are efficient and can handle virtually any size file. The <TT>emacs</TT> editor is better suited to complex editing tasks and comes with an online help facility, but for simple editing jobs, either editor is equally good. It comes down to whichever one you feel more comfortable using.</P>

<H3><A NAME="Heading3"></A><FONT COLOR="#000077">The Editing Functions</FONT></H3>

<P>Although there are a variety of text editors for Linux that have different interfaces, they all basically do the same things. Any useful text editor should support the following features at a minimum.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Inserting and Deleting Text</FONT></H4>

<P>The most intrinsic function of a text editor is to allow you to enter and erase characters as you see fit. This also implies that you have complete control over the movement of the cursor and its placement in the text.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">Reading and Writing Files</FONT></H4>

<P>Because you will want to save the text files that you create for future use and reuse, an editor can write your text to an external file. Whenever you need to make changes to your file, an editor can read the file from disk. A nice feature is that text editors are designed to accommodate ASCII-formatted files, so an editor (such as <TT>emacs</TT>) can read any file written by another editor (such as <TT>vi</TT>), and vice versa.</P>

<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Searching Text</FONT></H4>

<P>Personally scanning line after line of a large file for instances of a particular word is either a great way to improve your powers of concentration or an exercise in self-torture. That is why text editors provide sophisticated search capabilities. These include the use of regular expressions, as well as fixed strings. Remember that regular expressions include metacharacters (such as <TT>.</TT>, <TT>?</TT>, and <TT>*</TT>) that replace and expand unknown text patterns.</P>

<P>Editors also support search-and-replace functions that allow you to change multiple instances of a string pattern with a single command.</P>

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

<P>Because there is no guarantee that the way text is initially typed into a file is the way it should forever remain, editors provide you with the means to copy, cut, and move (or paste) blocks of text. These blocks can range in size from several pages to a single character. The distinction between copying and cutting text is that cutting deletes the selected block of text after it has been copied to a buffer, whereas copying does not.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">Editing Buffers</FONT></H4>

<P>What is a buffer, you ask? <I>Buffers</I> are places in the memory of the editing program where text can reside as you make changes to a file. For example, the first time you edit a file, the text you have entered actually exists in a buffer that is written to an external file when you do a save. Buffers can also be used at other times in editing, particularly when it is necessary to temporarily move a block of text to memory as you make changes (in other words, cutting and pasting). Many editors allow you to manage multiple buffers simultaneously.</P>

<P>These editors have many commands that are not fully detailed in this chapter. Before engaging in any long and arduous editing task, consult the man page for the editor you are using. There may be an easier way of doing whatever it is that you want to do. As you gain experience with an editor, you will discover convenient shortcuts and functions to perform your most tedious editing chores.</P>

<H3><A NAME="Heading9"></A><FONT COLOR="#000077">The vi Editor</FONT></H3>

<P>The <TT>vi</TT> editor is installed with virtually every UNIX system in existence. Because of this, <TT>vi</TT> is considered by many to be the default text editor of the UNIX system (upon which Linux is based). <TT>vi</TT> has two modes of operation and terse commands, both of which make it a somewhat more difficult editor to learn than <TT>emacs</TT>. However, it is a useful editor to learn if <TT>emacs</TT> has not been installed on your Linux system.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch15/295-298.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="304-307.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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