📄 ch09_01.htm
字号:
<html><head><title>The ex Editor (UNIX in a Nutshell: System V Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Arnold Robbins" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="1-56592-427-4" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="UNIX in a Nutshell: System V Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Book Title" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch08_10.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch09_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h1 class="chapter">Chapter 9. The ex Editor</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch09_01.htm#sect1">Syntax of ex Commands</a><br /><a href="ch09_02.htm">Alphabetical Summary of ex Commands</a><br /></p></div><p><a name="unut-ch-9-ix-ex-editor" />The <tt class="literal">ex</tt> line editor servesas the foundation for the screeneditor <tt class="literal">vi</tt>.Commands in <tt class="literal">ex</tt>work on the current line or on a range of lines in a file.Most often, you use <tt class="literal">ex</tt> from within <tt class="literal">vi</tt>.In <tt class="literal">vi</tt>, <tt class="literal">ex</tt> commands are precededby a colon and entered by pressing Return.</p><p>You can also invoke <tt class="literal">ex</tt> on its own--from the command line--just as you would invoke <tt class="literal">vi</tt>.(You could execute an <tt class="literal">ex</tt> script this way.)You can also use the <tt class="literal">vi</tt> command <tt class="literal">Q</tt>to quit the <tt class="literal">vi</tt> editor and enter <tt class="literal">ex</tt>.</p><p>This chapter presents the following topics:</p><ul><li><p>Syntax of <tt class="literal">ex</tt> commands</p></li><li><p>Alphabetical summary of commands</p></li></ul><p>For more information, see <em class="citetitle">Learning the viEditor</em>, listed in the <a href="biblio.htm">Bibliography</a>.</p><div class="sect1"><a name="unut-ch-9-sect-1" /><h2 class="sect1"><a name="sect1" />9.1. Syntax of ex Commands</h2><p><a name="IXT-9-123167" /><a name="IXT-9-123168" />To enter an <tt class="literal">ex</tt> command from <tt class="literal">vi</tt>, type:</p><p><tt class="userinput"><b>:</b></tt>[<em class="replaceable"><tt>address</em>] <em class="replaceable">command</em> [<em class="replaceable">options</tt></em>]</p><p>An initial <tt class="literal">:</tt> indicates an <tt class="literal">ex</tt> command. As you type the command, it is echoed on the status line. Enter the command by pressing the Return key.<em class="emphasis">address</em> is the line number or rangeof lines that are the object of <em class="emphasis">command</em>.<em class="emphasis">options</em> and <em class="emphasis">addresses</em> are described below.<tt class="literal">ex</tt> commands are described in <a href="ch09_02.htm#unut-ch-9-sect-2">Section 9.2</a>.</p><p>You can exit <tt class="literal">ex</tt> in several ways:</p><dl><dt><tt class="literal">:x</tt></dt><dd>Exit (save changes and quit).</p></dd><dt><tt class="literal">:q!</tt></dt><dd>Quit without saving changes.</p></dd><dt><tt class="literal">:vi</tt></dt><dd>Switch to the <tt class="literal">vi</tt> editor on the current file.</p></dd></dl><a name="unut-ch-9-sect-1.1" /><div class="sect2"><h3 class="sect2">9.1.1. Addresses</h3><p><a name="IXT-9-123169" />If no address is given, the current line is the object of the command.If the address specifies a range of lines, the format is:</p><p> <tt><em class="replaceable"><tt>x</em></tt><tt class="literal">,</tt><tt><em class="replaceable">y</tt></em></tt> </p><p>where <em class="emphasis">x</em></tt> and <em class="emphasis">y</em></tt> are the first and last addressed lines (<em class="emphasis">x</em></tt> must precede <em class="emphasis">y</em></tt>in the buffer).<em class="emphasis">x</em></tt> and <em class="emphasis">y</em></tt> may each be a line number or a symbol. Using <tt class="literal">;</tt> instead of <tt class="literal">,</tt> sets the current line to <em class="emphasis">x</em></tt> before interpreting <em class="emphasis">y</em></tt>.The notation <tt class="literal">1,$</tt> addresses all lines in the file,as does <tt class="literal">%</tt>. </p></div><a name="unut-ch-9-sect-1.2" /><div class="sect2"><h3 class="sect2">9.1.2. Address Symbols</h3><table border="1" cellpadding="3"><tr><td><tt class="literal">1,$</tt></td><td>All lines in the file.</td></tr><tr><td><tt><em class="replaceable"><tt>x</em></tt><tt class="literal">,</tt><tt><em class="replaceable">y</em></tt></td><td>Lines <em class="emphasis">x</em></tt> through <em class="emphasis">y</tt></em></tt>.</td></tr><tr><td><tt><em class="replaceable"><tt>x</em></tt><tt class="literal">;</tt><tt><em class="replaceable">y</em></tt></td><td><p>Lines <em class="emphasis">x</em></tt> through <em class="emphasis">y</em></tt>, with current line reset to <em class="emphasis">x</tt></em></tt>.</p></td></tr><tr><td><tt class="literal">0</tt></td><td>Top of file.</td></tr><tr><td><tt class="literal">.</tt></td><td>Current line.</td></tr><tr><td><tt><em class="replaceable"><tt>n</em></tt></td><td>Absolute line number <em class="emphasis">n</tt></em></tt>.</td></tr><tr><td><tt class="literal">$</tt></td><td>Last line.</td></tr><tr><td><tt class="literal">%</tt></td><td>All lines; same as <tt class="literal">1,$</tt>.</td></tr><tr><td><tt><em class="replaceable"><tt>x</em></tt><tt class="literal">-</tt><tt><em class="replaceable">n</em></tt></td><td><em class="emphasis">n</em></tt> lines before <em class="emphasis">x</tt></em></tt>.</td></tr><tr><td><tt><em class="replaceable"><tt>x</em></tt><tt class="literal">+</tt><tt><em class="replaceable">n</em></tt></td><td><em class="emphasis">n</em></tt> lines after <em class="emphasis">x</tt></em></tt>.</td></tr><tr><td><tt class="literal">-</tt>[<tt><em class="replaceable"><tt>n</em></tt>]</td><td>One or <em class="emphasis">n</tt></em></tt> lines previous.</td></tr><tr><td><tt class="literal">+</tt>[<tt><em class="replaceable"><tt>n</em></tt>]</td><td>One or <em class="emphasis">n</tt></em></tt> lines ahead.</td></tr><tr><td><tt class="literal">'</tt><tt><em class="replaceable"><tt>x</em></tt></td><td>Line marked with <em class="emphasis">x</tt></em></tt>.</td></tr><tr><td><tt class="literal">''</tt></td><td>Previous mark.</td></tr><tr><td><tt class="literal">/</tt><tt><em class="replaceable"><tt>pattern</em></tt><tt class="literal">/</tt></td><td>Forward to line matching <em class="emphasis">pattern</tt></em></tt>.</td></tr><tr><td><tt class="literal">?</tt><tt><em class="replaceable"><tt>pattern</em></tt><tt class="literal">?</tt></td><td>Backward to line matching <em class="emphasis">pattern</tt></em></tt>.</td></tr></table><p><p>See <a href="ch06_01.htm">Chapter 6</a>,for more information on using patterns.</p></div><a name="unut-ch-9-sect-1.3" /><div class="sect2"><h3 class="sect2">9.1.3. Options</h3><dl><dt><tt class="literal">!</tt></dt><dd>Indicates a variant form of the command, overriding the normal behavior.</p></dd><dt><i><em class="emphasis">count</em></tt></i></dt><dd>The number of times the command is to be repeated.Unlike in <tt class="literal">vi</tt> commands,<em class="emphasis">count</em></tt> cannot precede the command, becausea number preceding an <tt class="literal">ex</tt> command is treatedas a line address. For example, <tt class="literal">d3</tt>deletes three lines beginning with the current line;<tt class="literal">3d</tt> deletes line 3.</p></dd><dt><i><em class="emphasis">file</em></tt></i></dt><dd>The name of a file that is affected by the command.<tt class="literal">%</tt> stands for the current file; <tt class="literal">#</tt> stands for the previous file.</p></dd></dl></div></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch08_10.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch09_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">8.10. Setting Up vi</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">9.2. Alphabetical Summary of ex Commands</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2003</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,88,96" href="../index.htm"><area shape="rect" coords="90,0,165,96" href="../upt/index.htm"><area shape="rect" coords="168,1,253,107" href="../mac/index.htm"><area shape="rect" coords="255,0,335,97" href="../korn/index.htm"><area shape="rect" coords="337,0,415,109" href="../unixnut/index.htm"><area shape="rect" coords="417,0,512,122" href="../sedawk/index.htm"><area shape="rect" coords="514,0,605,105" href="../lunix/index.htm"><area shape="rect" coords="611,2,694,121" href="../vi/index.htm"> </map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -