Upcoming Events

Cloud Connect
Santa Clara
Feb 13-16, 2012

Cloud Connect brings together the entire cloud eco-system to better understand the transformation we're experiencing and promises to be the defining event of the cloud computing industry. Learn about the latest cloud technologies and platforms from thought leaders in Cloud Connect’s comprehensive conference.

Register Now!

More Events »

Subscribe to Newsletter

  • Keep up with all of the latest news and analysis on the fast-moving IT industry with Network Computing newsletters.
Sign Up


UnixWorld Online: Tutorial: Article No. 009: Part 8: Answers

Answers to Exercises

Hint for Indentation Exercise

Using a global command can cut the length of the command sequence roughly in half. The correct way to use it depends on something I did not explicitly say about global commands, but which you should be able to guess from what I did say.

 




































Answer to Indentation Exercise

A fairly simple way to handle both writing the tab-revised version of your file and keeping the original version in the editor buffer is this sequence:


:.g/^/%s/\({*\)^I^I/\1{/g|%s/^\({*\)^I/\1    /|%s/{/^I/g|w
u

The first line is pretty straightforward, excepting the initial global command. Otherwise it just replaces every pair of tabs at the start of a line with the dummy character ``{'', then changes any remaining solitary tab in the initial whitespace with four space characters, changes every dummy ``{'' to a single tab, and finally writes the file.

That initial global command seems silly, I know. It scans over just the current line, it marks that line without fail because every line has a starting point, and so it ends up running the remaining commands on the line for sure and exactly once. This is just what the command line would do without that initial global . So why is it there?

The answer is in that second line. When you run an undo after a global command, you don't just undo the last command the global ran; you undo every buffer change done by every command the global ran. (Note that the u is not preceded by a colon (``:''); it is a screen-mode command.) So as soon as the write is finished, the undo puts the entire buffer back as it was.

Print This Page


e-mail Send as e-mail

Research and Reports

Hypervisor Derby
August 2011

Network Computing: August 2011

TechWeb Careers