312-315.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 188 行
HTML
188 行
<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=312-315//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="309-312.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="315-317.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">A Summary of Essential Commands</FONT></H4>
<P>Table 16.1 is a summary of the more essential commands described in this chapter. You should consult the <TT>vi</TT> man page for more details on the many other <TT>vi</TT> commands.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 16.1.</B> Essential vi commands.
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="30%" ALIGN="LEFT">Command
<TH WIDTH="70%" ALIGN="LEFT">What it does
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD>i
<TD>Starts inserting text at the cursor
<TR>
<TD>h
<TD>Moves the cursor one character to the left
<TR>
<TD>j
<TD>Moves the cursor down one line
<TR>
<TD>k
<TD>Moves the cursor up one line
<TR>
<TD>l
<TD>Moves the cursor one character to the right
<TR>
<TD>Ctrl+f
<TD>Scrolls forward one screen
<TR>
<TD>Ctrl+b
<TD>Scrolls backward one screen
<TR>
<TD>ndd
<TD>Deletes the next <I>n</I> lines
<TR>
<TD>nyy
<TD>Yanks the next <I>n</I> lines into the unnamed buffer
<TR>
<TD VALIGN="TOP">p
<TD>Puts the contents of the unnamed buffer to the right of the cursor
<TR>
<TD>u
<TD>Undoes the last change
<TR>
<TD>:wq
<TD>Writes changes and exits <TT>vi</TT>
<TR>
<TD>:q!
<TD>Exits <TT>vi</TT> without saving changes
<TR>
<TD>:set all
<TD>Shows all <TT>set</TT> parameters and their values
<TR>
<TD>/string
<TD>Searches forward for <I>string</I>
<TR>
<TD COLSPAN="2"><HR>
<TR>
</TABLE>
<H3><A NAME="Heading20"></A><FONT COLOR="#000077">The emacs Editor</FONT></H3>
<P><TT>emacs</TT> has become the editor of choice for many users because of its online help facility and its extensive collection of editing commands. For programmers, <TT>emacs</TT> is especially attractive because it can be configured to format source code for a variety of languages such as C, C++, and Lisp. <TT>emacs</TT> is somewhat easier to learn than <TT>vi</TT>, but it also features a much larger set of commands.</P>
<H4 ALIGN="LEFT"><A NAME="Heading21"></A><FONT COLOR="#000077">Starting emacs</FONT></H4>
<P><TT>emacs</TT> is invoked from the command line by entering</P>
<!-- CODE SNIP //-->
<PRE>
emacs
</PRE>
<!-- END CODE SNIP //-->
<P>To start <TT>emacs</TT> with a file to be edited, enter</P>
<!-- CODE SNIP //-->
<PRE>
emacs <I>filename</I>
</PRE>
<!-- END CODE SNIP //-->
<P>If you start <TT>emacs</TT> 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 <I>mode line,</I> displays the name of the file being edited and the part of the file that you are looking at (for example, <TT>TOP</TT>,<TT>20%</TT>,<TT>BOT</TT>). The last line on the screen is the echo line, which <TT>emacs</TT> uses to display system messages and as a prompt for more input.</P>
<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Control and Meta Keys</FONT></H4>
<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, “How do I move the cursor around?” Before explaining this little detail, there are two keys that you should know about: the Control key and the Meta key. The Control key is used in most of the commands for <TT>emacs</TT>, but some use the Meta key instead. Commands in <TT>emacs</TT> consist of combinations of the Control or Meta key followed by some other character. It is necessary to hold 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.</P>
<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Moving the Cursor</FONT></H4>
<P>Now that you know about the Control key, we can talk about the cursor-movement commands. The basic ones that you need to remember are
</P>
<CENTER>
<TABLE WIDTH="90%"><TR>
<TD WIDTH="25%">Ctrl+f
<TD WIDTH="75%">Moves the cursor forward one character
<TR>
<TD>Ctrl+b
<TD>Moves the cursor back one character
<TR>
<TD>Ctrl+-p
<TD>Moves the cursor to the previous line
<TR>
<TD>Ctrl+n
<TD>Moves the cursor to the next line
<TR>
<TD>Ctrl+-a
<TD>Moves the cursor to the beginning of the line
<TR>
<TD>Ctrl+e
<TD>Moves the cursor to the end of the line
<TR>
</TABLE>
</CENTER>
<P>Most implementations of <TT>emacs</TT> conveniently map the first four movement commands to the arrow keys on the keyboard. Let’s edit a new file called <TT>asong2</TT>. Start <TT>emacs</TT> by entering the following command from the shell:</P>
<!-- CODE SNIP //-->
<PRE>
emacs asong2<Enter>
</PRE>
<!-- END CODE SNIP //-->
<P>Now enter the following text into the buffer:
</P>
<!-- CODE SNIP //-->
<PRE>
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!
</PRE>
<!-- END CODE SNIP //-->
<P>Now use the Ctrl+b command to move back through this lovely piece of poetry. Notice how the cursor jumps to the end of each line after reaching the beginning of the previous line. This works the same way in the opposite direction using the Ctrl+f command.
</P>
<P>Another useful way of moving around is by scrolling through a file one screen at a time. The command Ctrl+v moves the cursor forward one screen at a time. The command META+v moves the cursor in the opposite direction.</P>
<P>Like <TT>vi</TT>, <TT>emacs</TT> treats a sequence of non-whitespace characters as a word. You can move the cursor forward one word at a time with the META+f command. The META+b command moves back one word.</P>
<H4 ALIGN="LEFT"><A NAME="Heading24"></A><FONT COLOR="#000077">Quitting emacs</FONT></H4>
<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 Ctrl+x Ctrl+s. As you enter this command, notice how the command displays on the echo line as you type it. To quit <TT>emacs</TT> and return to the shell, enter the command Ctrl+x Ctrl+c. If you make changes that haven’t been saved using Ctrl+x Ctrl+s, <TT>emacs</TT> will ask for confirmation before quitting.</P>
<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">Deleting Text</FONT></H4>
<P>You can delete text in several ways. The Backspace (or Delete) key is used to erase the character that precedes the cursor. The command Ctrl+d deletes the character underneath the cursor, and Ctrl+k deletes, or “kills,” all characters from the cursor to the end of the line. Words can be deleted also: META+d deletes the word the cursor is currently located over, and META+Del (the Delete key) deletes the word just before the current word.
</P>
<P>If you ever find that you have done an edit that you didn’t want, simply press Ctrl+x u to undo the previous editing changes.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>Change your mind about a command? Press Ctrl+g to abort the current command operation.<HR></FONT>
</BLOCKQUOTE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="309-312.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="315-317.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?