📄 ch12_04.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 12] 12.4 Job Control and autowrite: Real Time Savers! </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:36:27Z"><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="ch12_01.htm"TITLE="12. Job Control"><LINKREL="prev"HREF="ch12_03.htm"TITLE="12.3 The "Current Job" Isn't Always What You Expect"><LINKREL="next"HREF="ch12_05.htm"TITLE="12.5 System Overloaded? Try Stopping Some Jobs "></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="ch12_03.htm"TITLE="12.3 The "Current Job" Isn't Always What You Expect"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 12.3 The "Current Job" Isn't Always What You Expect"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 12<BR>Job Control</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch12_05.htm"TITLE="12.5 System Overloaded? Try Stopping Some Jobs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 12.5 System Overloaded? Try Stopping Some Jobs "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1900">12.4 Job Control and autowrite: Real Time Savers! </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-13616"></A><ACLASS="indexterm"NAME="AUTOID-13619"></A>I see too many people using a series of commands like the ones that follow.Programmers do this when they write and compile programs.Writers use this when they're making a draft file and running it through theformatter.They're probably wasting a lot of time and effort:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>vi somefile</B></CODE> ...<EMCLASS="emphasis">Edit somefile, then quit vi</EM>...% <CODECLASS="userinput"><B>someprog somefile</B></CODE> ...<EMCLASS="emphasis">Process somefile</EM>...% <CODECLASS="userinput"><B>vi somefile</B></CODE> ...<EMCLASS="emphasis">Edit somefile again</EM>...% <CODECLASS="userinput"><B>someprog somefile</B></CODE> ...<EMCLASS="emphasis">Process somefile again</EM>...</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-13633"></A>Each time they restart <EMCLASS="emphasis">vi</EM>, they have to reset options and move thecursor to the place they were working before.After they restart, <EMCLASS="emphasis">vi</EM> has forgotten the previous search (the<EMCLASS="emphasis">n</EM> command), the previous action (the <CODECLASS="literal">.</CODE> command), theprevious regular expression, the named and numbered buffers...</P><PCLASS="para">If your system has<SPANCLASS="link">job control (<ACLASS="linkend"HREF="ch12_08.htm"TITLE="Job Control in a Nutshell ">12.8</A>)</SPAN>,that'll solve all these problems.[1]Instead of quitting <EMCLASS="emphasis">vi</EM>, get into command modeand write your buffer with the <CODECLASS="literal">:w</CODE> command.Stop the editor with the CTRL-z command.Then, process the file.When you're ready to do more editing, bring your <EMCLASS="emphasis">vi</EM> job back into theforeground with <EMCLASS="emphasis">fg</EM>.The editor will be just where it was.</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] If it doesn't, you can still use a<SPANCLASS="link">shell escape (<ACLASS="linkend"HREF="ch30_26.htm"TITLE="Shell Escapes: Running One UNIX Command While Using Another">30.26</A>)</SPAN>.</P></BLOCKQUOTE><PCLASS="para">Even better, you can set <EMCLASS="emphasis">vi</EM>'s option called <EMCLASS="emphasis">autowrite</EM>.If you've made any changes to the buffer before you press CTRL-z,<EMCLASS="emphasis">vi</EM> will automatically write the buffer.You won't need to remember to type <CODECLASS="literal">:w</CODE> before you stop the editor.You can set <EMCLASS="emphasis">autowrite</EM> at a colon (<CODECLASS="literal">:</CODE>) prompt, but I set it in my<SPANCLASS="link"><EMCLASS="emphasis">.exrc</EM> file (<ACLASS="linkend"HREF="ch30_06.htm"TITLE="Local Settings for vi and ex ">30.6</A>)</SPAN>instead.</P><PCLASS="para">[You don't absolutely have to write your file before suspending<EMCLASS="emphasis">vi</EM>.It's a good piece of advice, but not required by the jobcontrol mechanism.Typing CTRL-z will suspend the editor whetheryou've written out your files or not. -<EMCLASS="emphasis">TOR</EM> ]</P><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="ch12_03.htm"TITLE="12.3 The "Current Job" Isn't Always What You Expect"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 12.3 The "Current Job" Isn't Always What You Expect"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="ch12_05.htm"TITLE="12.5 System Overloaded? Try Stopping Some Jobs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 12.5 System Overloaded? Try Stopping Some Jobs "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">12.3 The "Current Job" Isn't Always What You Expect</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">12.5 System Overloaded? Try Stopping Some Jobs </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 + -