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

📄 ch30_34.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 30] 30.34 vi Line Commands vs. Character Commands </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:45:55Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch30_01.htm"TITLE="30. vi Tips and Tricks"><LINKREL="prev"HREF="ch30_33.htm"TITLE="30.33 Fixing Typos with vi Abbreviations "><LINKREL="next"HREF="ch30_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch30_33.htm"TITLE="30.33 Fixing Typos with vi Abbreviations "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 30.33 Fixing Typos with vi Abbreviations "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 30<BR>vi Tips and Tricks</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch30_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 30.35 Out of Temporary Space? Use Another Directory "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0159">30.34 vi Line Commands vs. Character Commands </A></H2><PCLASS="para">[Quite a few <EMCLASS="emphasis">vi</EM> users understand how to build <EMCLASS="emphasis">vi</EM> commands withthe <EMCLASS="emphasis">(number)(command)(text object)</EM> model.But not too many people understand the difference between line commandsand character commands.This article explains that and gives some examples. -JP]</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-34382"></A>The <CODECLASS="literal">_</CODE> (underscore) command is very similar to the <CODECLASS="literal"></CODE> (caret)command in that it movesto the first non-blank character of the current line. The keydifference is that <CODECLASS="literal">_</CODE> is a <EMCLASS="emphasis">line</EM> command while <CODECLASS="literal"></CODE>is a <EMCLASS="emphasis">character</EM>command. This is important for all functions that read an &quot;address,&quot;for example, <CODECLASS="literal">d</CODE>, <CODECLASS="literal">y</CODE>, and <CODECLASS="literal">c</CODE>.</P><PCLASS="para">In fact, delete, yank, and so on all call a common internalroutine in <EMCLASS="emphasis">vi</EM> to get an &quot;address.&quot; If the address is of a particularcharacter, <EMCLASS="emphasis">vi</EM> does a character-mode delete or yank or whatever. Ifit is a line address, <EMCLASS="emphasis">vi</EM> does a line-mode operation. The&quot;address&quot; command may be any of the regular positioning commands(e.g., <CODECLASS="literal">W</CODE>,<CODECLASS="literal"> b</CODE>,<CODECLASS="literal"> $</CODE>, or<CODECLASS="literal"> /pattern/</CODE>) or the original character repeated (as in<CODECLASS="literal">dd</CODE> or <CODECLASS="literal">yy</CODE>).</P><PCLASS="para">Some examples are in<ACLASS="xref"HREF="ch30_34.htm#UPT-ART-159-TAB-0"TITLE="Examples of vi Character and Line Commands">Table 30.1</A>.</P><TABLECLASS="table"><CAPTIONCLASS="table"><ACLASS="title"NAME="UPT-ART-159-TAB-0">Table 30.1: Examples of vi Character and Line Commands</A></CAPTION><THEADCLASS="thead"><TRCLASS="row"VALIGN="TOP"><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Keystrokes</TH><THCLASS="entry"ALIGN="LEFT"ROWSPAN="1"COLSPAN="1">Results</TH></TR></THEAD><TBODYCLASS="tbody"><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">dd</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Deletes the current line.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">d'a</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Deletes all lines between the current line and the line containing mark<CODECLASS="literal">a</CODE>, inclusive.</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">d`a</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Deletes all characters between the current characterand the character at mark <CODECLASS="literal">a</CODE>. This works muchlike an Emacs <CODECLASS="literal">W</CODE> in that the two endpoints areconsidered to be between two characters. Note thata character-oriented delete may delete newlines.</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">c/accord/</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Changes all characters (<EMCLASS="emphasis">not</EM> lines!) between thecurrent character up to but not including the <CODECLASS="literal">a</CODE>in <CODECLASS="literal">accord</CODE>. (However, see the following Note.)</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">c?accord?</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Changes all characters between the current characterand the <CODECLASS="literal">accord</CODE>, including the word <CODECLASS="literal">accord</CODE>.</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">yj</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">Yanks two lines, the current line and the one below.</TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">yH</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Yanks all the lines from the top of the screen to the current line, inclusive.</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">&lt;G</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Unindents or &quot;dedents&quot; the lines between the current line and thelast line, inclusive. (The variable <CODECLASS="literal">shiftwidth</CODE>determines the amount of dedenting.) Note thatthis command turns character addresses into lineaddresses (so does <CODECLASS="literal">&gt;</CODE>).</P></TD></TR><TRCLASS="row"VALIGN="TOP"><TDCLASS="entry"ROWSPAN="1"COLSPAN="1">!}fmt</TD><TDCLASS="entry"ROWSPAN="1"COLSPAN="1"><PCLASS="para">Runs the lines between the current line and theend of the paragraph through the program<SPANCLASS="link"><EMCLASS="emphasis">fmt</EM> (<ACLASS="linkend"HREF="ch30_37.htm"TITLE="Neatening Lines ">30.37</A>)</SPAN>.</P></TD></TR></TBODY></TABLE><BLOCKQUOTECLASS="note"><PCLASS="para"><STRONG>NOTE:</STRONG> If you have <CODECLASS="literal">wrapscan</CODE> set, asearch like <CODECLASS="literal">c?accord?</CODE> may wrap from the beginning of the file tothe end. This can cause unexpected results, and is one reasonwhy I have <CODECLASS="literal">set nows</CODE> in my <EMCLASS="emphasis">.exrc</EM>.Unfortunately, turning off <CODECLASS="literal">wrapscan</CODE> breaks<SPANCLASS="link"><EMCLASS="emphasis">tags</EM> (<ACLASS="linkend"HREF="ch30_28.htm"TITLE="Keep Track of Functions and Included Files with ctags and tags">30.28</A>)</SPAN>in many versions of <EMCLASS="emphasis">vi</EM>.</P></BLOCKQUOTE><PCLASS="para"><EMCLASS="emphasis">vi</EM> combines the repeat count, if any, on the command character withthe repeat count on the motion command, so that <CODECLASS="literal">2y2j</CODE> yanks fivelines. Interestingly, <CODECLASS="literal">2y2_</CODE> yanks 4&nbsp;lines (so does <CODECLASS="literal">2y2y</CODE>) sincethe <CODECLASS="literal">_</CODE> command moves down (repeat count minus 1) lines. Beware,however, of using repeat counts on all of the motion commands; they'renot all implemented in the same way. <CODECLASS="literal">4$</CODE> moves to the end of the thirdline below the current; <CODECLASS="literal">4</CODE> merely moves to the first non-blankcharacter of the current line. <CODECLASS="literal">|</CODE> (vertical bar) is a synonym for<CODECLASS="literal">0</CODE> (zero); given a repeat count it goes that many characters to the rightof the beginning of the line (as if you had typed <CODECLASS="literal">|</CODE> (<EMCLASS="emphasis">rept-1</EM>)<CODECLASS="literal">l</CODE>). (Exercise for the reader: why can't you give a repeat countto <CODECLASS="literal">0</CODE>?)</P><PCLASS="para">Uppercase letters do different things depending on the command. Theexact actions may not always seem sensible, but typically they affectthe &quot;current line&quot;: <CODECLASS="literal">D</CODE> acts like <CODECLASS="literal">d$</CODE>; <CODECLASS="literal">C</CODE> actslike <CODECLASS="literal">c$</CODE>; <CODECLASS="literal">Y</CODE> acts like <CODECLASS="literal">yy</CODE>. The list must merelybe memorized, or you can usea good <EMCLASS="emphasis">vi</EM> reference guide.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">CT</SPAN> <SPANCLASS="bibliomisc">in <ACLASS="systemitem.newsgroup"HREF="news:net.unix">net.unix</A> on Usenet, 19 March 1984</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="ch30_33.htm"TITLE="30.33 Fixing Typos with vi Abbreviations "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 30.33 Fixing Typos with vi Abbreviations "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="ch30_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 30.35 Out of Temporary Space? Use Another Directory "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">30.33 Fixing Typos with vi Abbreviations </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">30.35 Out of Temporary Space? Use Another Directory </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 + -