307-309.html

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

HTML
139
字号
<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=307-309//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

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

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

<TD><A HREF="309-312.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">Moving the Cursor</FONT></H4>

<P>Moving the cursor around in <TT>vi</TT> essentially involves the following four keys:</P>

<CENTER>

<TABLE WIDTH="80%"><TR>

<TD WIDTH="30%">h

<TD WIDTH="70%">Moves the cursor one space 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 space to the right

<TR>

</TABLE>

</CENTER>

<P>These keys can perform their operations only when <TT>vi</TT> is in command mode. For convenience, most implementations of <TT>vi</TT> map these keys to their directional counterparts on the keyboard arrow keys.</P>

<P><TT>vi</TT> enables you to move through a file in bigger &#147;leaps&#148; as well. Below are some commands for scrolling more than one line at a time:</P>

<CENTER>

<TABLE WIDTH="80%"><TR>

<TD WIDTH="30%">Ctrl&#43;u

<TD WIDTH="70%">Scrolls up a half-screen

<TR>

<TD>Ctrl&#43;d

<TD>Scrolls down a half-screen

<TR>

<TD>Ctrl&#43;f

<TD>Scrolls down one full screen

<TR>

<TD>Ctrl&#43;b

<TD>Scrolls up one full screen

<TR>

</TABLE>

</CENTER>

<P>The size of these movements largely depends on the terminal settings.

</P>

<P>It is also possible to move the cursor to a specific line in a file. If you want to move to the fifth line, type <TT>10G</TT> or <TT>:10</TT> while in command mode. <TT>G</TT> by itself moves the cursor to the end of the file. The cursor does not move if the number given is not applicable (for example, typing <TT>:10</TT> in an eight-line file has no effect).</P>

<TT>vi</TT> also enables you to move the cursor one word at a time. A word is defined as any sequence of non-whitespace characters. To move to the beginning of the next word on the current line, press <TT>w</TT>. Press <TT>b</TT> to move the cursor to the beginning of the current or previous word.

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

<P><TT>vi</TT> has commands for deleting characters, lines, and words. <I>Deletion</I> means that the selected text is removed from the screen but is copied into an unnamed text buffer from which it can be retrieved.</P>

<P>To delete a word, use the <TT>dw</TT> command. If you want to delete the word to the right of the cursor, type <TT>dw</TT>. You can also delete several words at a time. For example, the command <TT>4dw</TT> deletes the next four words on the current line.</P>

<P>Lines can be deleted individually or by specifying a range of lines to delete. To delete the current line, enter <TT>dd</TT>. The command <TT>4dd</TT> deletes four lines (the current line and three below it). <TT>dG</TT> deletes all lines from the current one to the end of the file.</P>

<P>On the current line, you can delete in either direction: <TT>d^</TT> deletes backward to the beginning of the line; <TT>d&#36;</TT> (or <TT>D</TT>) deletes forward to the end of the line.</P>

<P>To delete individual characters, <TT>x</TT> deletes the character underneath the cursor, and <TT>X</TT> deletes the character to the left of the cursor. Both of these commands accept a number modifier: For example, <TT>4x</TT> deletes the current character and the four characters to the right.</P>

<P>Unwanted changes such as deletions can be immediately undone by the <TT>u</TT> command. This &#147;rolls back&#148; the last edit made.</P>

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

<P>Moving sections of text around in a file basically requires three steps:

</P>

<DL>

<DD><B>1.</B>&nbsp;&nbsp;&#147;Yank&#148; the text into a buffer.

<DD><B>2.</B>&nbsp;&nbsp;Move the cursor to where you want to insert the text.

<DD><B>3.</B>&nbsp;&nbsp;Place the text from the buffer at the new location.

</DL>

<P><I>Yanking</I> text means to copy it into either a named or unnamed buffer. The <I>unnamed buffer</I> is a temporary storage space in memory that is continually overwritten by successive yanks. <TT>vi</TT> has 26 named buffers that correspond to each letter of the alphabet.</P>

<P>To yank the current line into the unnamed buffer, the command is <TT>yy</TT> or <TT>Y</TT>. These commands can be modified by a number indicating how many lines beneath the cursor are to be yanked. For example, the command</P>

<!-- CODE SNIP //-->

<PRE>

3yy

</PRE>

<!-- END CODE SNIP //-->

<P>in your file <TT>asong</TT> (with the cursor on the top line) yanks the following text into the temporary buffer:</P>

<!-- CODE SNIP //-->

<PRE>

Down I walk

by the bay,

Where I can

</PRE>

<!-- END CODE SNIP //-->

<P>This text can also be yanked into the named buffer <TT>a</TT> by the following command:</P>

<!-- CODE SNIP //-->

<PRE>

&#147;a3yy

</PRE>

<!-- END CODE SNIP //-->

<P>The double quote (<TT>&#148;</TT>) tells the yank command to overwrite the contents of the named buffer <TT>a</TT>. If you type a capital <TT>A</TT> instead of a lowercase <TT>a</TT>, the three lines are appended to the end of the <TT>a</TT> buffer. This overwrite-versus-append concept works the same for all the named buffers.</P>

<P>If you move the cursor to the end of the file using the <TT>:&#36;</TT> command, you can then paste the contents of the unnamed buffer to the end of the file. This is done using the <TT>p</TT> command, which pastes the contents of a buffer to the right of the cursor (<TT>P</TT> pastes to the left of the cursor). The paste command can also specify a named buffer in the same way as the yank command:</P>

<!-- CODE SNIP //-->

<PRE>

&#147;ap

</PRE>

<!-- END CODE SNIP //-->

<P>Yanks can also be performed on words using the command <TT>yw</TT>. This command can also use named buffers and accepts numeric modifiers.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

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

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

<TD><A HREF="309-312.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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