📄 ch30_36.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 30] 30.36 The ex Open Mode Can Be Handy </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:45:59Z"><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_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "><LINKREL="next"HREF="ch30_37.htm"TITLE="30.37 Neatening Lines "></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_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 30.35 Out of Temporary Space? Use Another Directory "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_37.htm"TITLE="30.37 Neatening Lines "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 30.37 Neatening Lines "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-6950">30.36 The ex Open Mode Can Be Handy </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-6950-IX-VI-EDITOR-EX-OPEN-MODE"></A><ACLASS="indexterm"NAME="UPT-ART-6950-IX-EX-EDITOR-OPEN-MODE"></A><ACLASS="indexterm"NAME="AUTOID-34557"></A>Most <EMCLASS="emphasis">vi</EM> users hate it when they start the editor and get a messagelike one of these:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Visual needs addressable cursor or upline capability[Using open mode]</PRE></BLOCKQUOTE></P><PCLASS="para">Those folks usually say (or think) something choice like "how the #&@!do I get to fullscreen mode?"If you're one of those people, wait.You might get to <EMCLASS="emphasis">like</EM> the <EMCLASS="emphasis">ex</EM> open mode!</P><PCLASS="para">Before I show you an example of open mode, I'll mention another placewhere it's nice: on slow dialup lines or sluggish network connections,where your screen fills slowly and you're always waiting for it toredraw.It's also very useful if you're using a window system and <EMCLASS="emphasis">vi</EM>doesn't seem to understand how many lines are in your window - for quickediting, it can be easier to switch to open mode for a minute than totry to fix the window.</P><PCLASS="para">The open mode is something like <EMCLASS="emphasis">vi</EM> on a one-line screen.It's different from other UNIX line-mode editors like <EMCLASS="emphasis">ed</EM> or thestandard colon-prompt mode of <EMCLASS="emphasis">ex</EM>, though.In open mode, you use the normal fullscreen <EMCLASS="emphasis">vi</EM> commands - one lineat a time.For example, to exit, type <CODECLASS="literal">ZZ</CODE> just like you do in fullscreen mode.</P><PCLASS="para">If you've got a fair amount of experience with <EMCLASS="emphasis">vi</EM>, the easiest wayto learn about open mode is to jump in and try it - after a littleexplanation, that is.There are three ways to get into open mode:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">If you're thrown into <EMCLASS="emphasis">ex</EM> mode and given a colon (<CODECLASS="literal">:</CODE>)prompt, type this command and press RETURN:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">:<CODECLASS="userinput"><B>open</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"></P></LI><LICLASS="listitem"><PCLASS="para">If you have a choice - on a slow network connection, forexample - start open mode from the command line.Depending on your version of <EMCLASS="emphasis">vi</EM>, use oneof the following commands:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ex +open</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE>% <CODECLASS="userinput"><B>ex -c open</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P></LI><LICLASS="listitem"><PCLASS="para">If you're already in <EMCLASS="emphasis">vi</EM>'s fullscreen mode, switch to open modeby typing <CODECLASS="literal">Q</CODE> to get an <EMCLASS="emphasis">ex</EM> colon (<CODECLASS="literal">:</CODE>) prompt.Then type the command <CODECLASS="literal">open</CODE> and press RETURN.</P></LI></UL><PCLASS="para">When you start open mode, the editor will display the current lineand put your cursor at the start of it.</P><PCLASS="para"></P><DLCLASS="variablelist"><DTCLASS="term">Keystrokes</DT><DDCLASS="listitem"><PCLASS="para">Result</P></DD></DL><PCLASS="para"><CODECLASS="literal">ex +open afile</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[Using open mode]"afile" 47 lines, 1943 characters<UCLASS="cursor">I</U>n the beginning, there was a cursor.</PRE></BLOCKQUOTE></P><PCLASS="para">Open the file <EMCLASS="emphasis">afile</EM> in open mode.Notice that the prompt line, which shows the filename and sizeat the bottom of the screen in <EMCLASS="emphasis">vi</EM>, is printed first during open mode.That's because open mode always prints line by line.Next, the first line of the file is displayed.Your cursor is at the start of the line.</P><PCLASS="para"><CODECLASS="literal">2w</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[Using open mode]"afile" 47 lines, 1943 charactersIn the <UCLASS="cursor">b</U>eginning, there was a cursor.</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">vi</EM> command <CODECLASS="literal">2w</CODE> moves the cursor forward two words.</P><PCLASS="para"><CODECLASS="literal">j</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[Using open mode]"afile" 47 lines, 1943 charactersIn the beginning, there was a cursor.The scr<UCLASS="cursor">e</U>en was blank and without characters.</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">vi</EM> command <CODECLASS="literal">j</CODE> moves the cursor down one line.NOTE: On some versions, this command will print only the first fewcharacters of the new line - up to the place where the cursor sits.So, instead of <CODECLASS="literal">j</CODE>, I usually use the RETURN command to painta whole line and move the cursor to the front of it.</P><PCLASS="para"><CODECLASS="literal">k</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[Using open mode]"afile" 47 lines, 1943 charactersIn the beginning, there was a cursor.The screen was blank and without characters.In the <UCLASS="cursor">b</U>eginning, there was a cursor.</PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">vi</EM> command <CODECLASS="literal">k</CODE> moves the cursor up one line - to theprevious line.This is open mode, so the previous lines scroll away.To keep from getting confused, remember: the line with the cursor is theone you're editing now.NOTE: As in the previous step, the <CODECLASS="literal">k</CODE> command may not print allof the line.In that case, the minus (<CODECLASS="literal">-</CODE>) command is better.</P><PCLASS="para"><CODECLASS="literal">cwend</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">[Using open mode]"afile" 47 lines, 1943 charactersIn the beginning, there was a cursor.The screen was blank and without characters.In the en<UCLASS="cursor">d</U>, there was a cursor.</PRE></BLOCKQUOTE></P><PCLASS="para">Typing <CODECLASS="literal">cw</CODE> puts you into <EMCLASS="emphasis">vi</EM>'s text-input mode to change the word<EMCLASS="emphasis">beginning</EM> to <EMCLASS="emphasis">end</EM>.Press ESC to go back to command mode.</P><PCLASS="para">This might take some getting used to.But once you learn the idea behind open mode, it can be handy to know.</P><ACLASS="indexterm"NAME="AUTOID-34654"></A><ACLASS="indexterm"NAME="AUTOID-34655"></A><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="ch30_35.htm"TITLE="30.35 Out of Temporary Space? Use Another Directory "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 30.35 Out of Temporary Space? Use Another Directory "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_37.htm"TITLE="30.37 Neatening Lines "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 30.37 Neatening Lines "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">30.35 Out of Temporary Space? Use Another Directory </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.37 Neatening Lines </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 & 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 + -