home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 12.3 The "Current Job" Isn't Always What You Expect Chapter 12
Job Control
Next: 12.5 System Overloaded? Try Stopping Some Jobs
 

12.4 Job Control and autowrite: Real Time Savers!

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 the formatter. They're probably wasting a lot of time and effort:

% vi somefile


   ...Edit somefile, then quit vi
...
% someprog somefile


   ...Process somefile
...
% vi somefile


   ...Edit somefile again
...
% someprog somefile


   ...Process somefile again
...

Each time they restart vi , they have to reset options and move the cursor to the place they were working before. After they restart, vi has forgotten the previous search (the n command), the previous action (the . command), the previous regular expression, the named and numbered buffers...

If your system has job control (12.8 ) , that'll solve all these problems. [1] Instead of quitting vi , get into command mode and write your buffer with the :w command. Stop the editor with the CTRL-z command. Then, process the file. When you're ready to do more editing, bring your vi job back into the foreground with fg . The editor will be just where it was.

[1] If it doesn't, you can still use a shell escape (30.26 ) .

Even better, you can set vi 's option called autowrite . If you've made any changes to the buffer before you press CTRL-z, vi will automatically write the buffer. You won't need to remember to type :w before you stop the editor. You can set autowrite at a colon (: ) prompt, but I set it in my .exrc file (30.6 ) instead.

[You don't absolutely have to write your file before suspending vi . It's a good piece of advice, but not required by the job control mechanism. Typing CTRL-z will suspend the editor whether you've written out your files or not. -TOR  ]

- JP


Previous: 12.3 The "Current Job" Isn't Always What You Expect UNIX Power Tools Next: 12.5 System Overloaded? Try Stopping Some Jobs
12.3 The "Current Job" Isn't Always What You Expect Book Index 12.5 System Overloaded? Try Stopping Some Jobs

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System