DB2 LUW Performance: Using the vi (Very Intuitive) editor


Posted by Scott on December 25, 2010, 10:09 am
in DB2 Performance How-To ( DB2 Performance)

I recently spoke with a customer that was rehosting a mainframe DB2/CICS/COBOL application to pSeries AIX. I did this in the mid-90's. When you find yourself in the UNIX or Linux world, you need to know how to use the VI editor. Since I'm now stranded in the ATL airport on Christmas day, this mini VI class is my "gift" to the DB2 LUW community. icon_smile
I recently spoke with a customer that was rehosting a mainframe DB2/CICS/COBOL application to pSeries AIX. I did this in the mid-90's. When you find yourself in the UNIX or Linux world, you need to know how to use the VI editor. Since I'm now stranded in the ATL airport on Christmas day, this mini VI class is my "gift" to the DB2 LUW community. icon_smile





From your command prompt, to begin using vi, simply type vi followed by the name of the file you want to edit:

$ vi myfilename.txt


vi has two basic modes of operation: command mode and input mode.


When you first start vi, you are in command mode and vi waits for your instructions. Many useful commands are preceded by the colon ":" character.


Some of the more useful commands include:


If you are in INPUT mode and want to return to COMMAND mode, hit your ESC key. You will find that you will hit the ESC key quite a bit.


INPUT MODE


While in COMMAND mode, you switch to INPUT mode by hitting particular characters:

So, that's the basics. You can now start vi, use one of the INPUT mode commands to type some characters, then hit ESC (return to COMMAND mode), then type :wq to save your work and exit.


IMPORTANT COMMANDS


You'll probably need or want to navigate around within your file, so let's look at commands to help you get around next:

Repeating commands


If you want to repeat a particular command some number of times, type the number of times to repeat followed by the command that you want to repeat. This is incredibly powerful and useful. Some examples:

Probably the most commonly used repeat command is the dot or period key. After executing a command, just hit the "." key to repeat it.

Deleting stuff


There will likely come a time when you want to get rid of something in a file. Here are your important commands:

Finding Stuff


vi will help you search forwards or backwards:

Find and Replace


Often times we have the need to replace strings in a file. This is tricky, but very powerful.


Type a colon ":" followed by the lowercase letter "s" (for substitute).

Follow the letter "s" with a slash "/"

Type the old string you want to get rid of

Type another slash "/"

Type the new string that you want to replace the old one with

Type another slash "/" followed by a lowercase letter g and hit enter!

Here's and example:
:s/ERROR MESSAGE/SUCCESS Message/g


Well then, my time is up as my flight will soon be boarding. I hope this quick primer on the very intuitive (vi) editor will be helpful to many of you. Even experienced folks might find a few useful tricks in this.


Happy Holidays,

Scott


PS - Please check out The DB2Night Show™ Edutainment Webinar series at www.DB2NightShow.com

Post from : http://www.dbisoftware.com/blog/db2_performance.php
Printed from : http://www.dbisoftware.com/blog/db2_performance.php?id=224