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

📄 ch31_04.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
> on a line will change it tohave <CODECLASS="literal">H4</CODE>.Move through your file (maybe with a search: <CODECLASS="literal">/STRONG</CODE> ...<CODECLASS="literal">n</CODE> ...), typing <CODECLASS="literal">@a</CODE> or <CODECLASS="literal">@b</CODE> as you go.Or use <CODECLASS="literal">@@</CODE> to make the same change you made on a previous line.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-9913-SECT-1.2">31.4.2 Combining @-Functions </A></H3><PCLASS="para">An <CODECLASS="literal">@</CODE>-function can execute other <CODECLASS="literal">@</CODE>-functions.For example, here are four lines ready for storing as <CODECLASS="literal">@a</CODE> through<CODECLASS="literal">@d</CODE>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">0l@c$T/@c   <ICLASS="lineannotation">...becomes @a</I>0l@d$T/@d   <ICLASS="lineannotation">...becomes @b</I>cwH3^[   <ICLASS="lineannotation">...becomes @c</I>cwH4^[   <ICLASS="lineannotation">...becomes @d</I></PRE></BLOCKQUOTE></P><PCLASS="para">See that the definition of <CODECLASS="literal">@a</CODE> has <CODECLASS="literal">@c</CODE> in it twice?When you execute <CODECLASS="literal">@a</CODE>, it will do <CODECLASS="literal">0l</CODE> to move to thesecond character on the line, then do <CODECLASS="literal">@c</CODE> to change the wordto <CODECLASS="literal">H3</CODE>, move to the end of the line and use <CODECLASS="literal">@c</CODE> again.Calling one <CODECLASS="literal">@</CODE>-function from another can save re-typingrepetitive commands.</P><PCLASS="para">A disadvantage is that <CODECLASS="literal">@@</CODE> won't always work as you might expect.If you type <CODECLASS="literal">@a</CODE> to make a change in one place,then move somewhere else and type <CODECLASS="literal">@@</CODE>, the <CODECLASS="literal">@@</CODE> willdo what <CODECLASS="literal">@c</CODE> does (instead of what you might have wanted,<CODECLASS="literal">@a</CODE>).That's because the <CODECLASS="literal">@a</CODE> function finishes by doing a <CODECLASS="literal">@c</CODE>.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-9913-SECT-1.3">31.4.3 Reusing a Definition </A></H3><PCLASS="para">You don't have to delete the definition line into a buffer with <CODECLASS="literal">dd</CODE>.If you think you might need to fine-tune the command, you can yank(copy) it into a buffer with a command like <CODECLASS="literal">&quot;ay$</CODE>.Then, if you need to revise the command, re-edit the line and type<CODECLASS="literal">&quot;ay$</CODE> to put the revised version into the buffer.Or use <CODECLASS="literal">&quot;by$</CODE> to copy the revised line into another buffer.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-9913-SECT-1.4">31.4.4 Newlines in an @-Function </A></H3><PCLASS="para">Stored <CODECLASS="literal">@</CODE>-functions can span multiple lines.For example, if you delete the following four lines with <CODECLASS="literal">&quot;z4dd</CODE>,typing <CODECLASS="literal">@z</CODE> will open a new line below (<CODECLASS="literal">o</CODE>) andinsert four new lines of text:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">oThis is the new line one.This is the new line two.This is the third line.This is the fourth.^[</PRE></BLOCKQUOTE></P><PCLASS="para">After you execute the function with <CODECLASS="literal">@z</CODE>,your cursor will move to the line below the new fourth line.Why?Because you included the newlines (RETURNs) in the buffer; eachRETURN moves down a line&nbsp;- including the RETURN after thelast ESC.</P><PCLASS="para">If you don't want that, there are two ways to fix it:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">Delete the first three lines, including the newlines, into the bufferby typing <CODECLASS="literal">&quot;z3dd</CODE>.Delete the fourth line, without its newline, and <EMCLASS="emphasis">append</EM> it tothe buffer by typing <CODECLASS="literal">&quot;ZD</CODE>.(An uppercase letter like <CODECLASS="literal">Z</CODE> appends to a named buffer.<CODECLASS="literal">D</CODE> deletes all of a line except the newline.)</P><PCLASS="para">Some versions of <EMCLASS="emphasis">vi</EM> will delete four lines, without the lastnewline, when you use <CODECLASS="literal">&quot;z4D</CODE>.</P></LI><LICLASS="listitem"><PCLASS="para">Type all of the text onto a single line; embed the newlines inthat line by typing <KBDCLASS="keycap">[CTRL-v]</KBD> <KBDCLASS="keycap">[RETURN]</KBD>between each finished line.It'll look like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">oThis is the new line one.^MThis is the new line two.^MThis is the new...</PRE></BLOCKQUOTE></P><PCLASS="para">Delete that long line into your buffer with <CODECLASS="literal">&quot;zD</CODE>.Because <CODECLASS="literal">D</CODE> doesn't delete the final newline, your cursor willstay at the end of the fourth new line after you execute the <CODECLASS="literal">@z</CODE>.</P></LI></UL><ACLASS="indexterm"NAME="AUTOID-35196"></A><ACLASS="indexterm"NAME="AUTOID-35197"></A></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_03.htm"TITLE="31.3 What You Lose When You Use map! "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 31.3 What You Lose When You Use map! "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_05.htm"TITLE="31.5 Keymaps for Pasting into a Window Running vi "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 31.5 Keymaps for Pasting into a Window Running vi "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">31.3 What You Lose When You Use map! </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">31.5 Keymaps for Pasting into a Window Running vi </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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