Team with the best
Db2® LUW Performance Tools
company in the World

DB2 LUW Performance: Using the vi editor - Part 2

January 5, 2011, 3:29 pm
Posted by Scott in DB2 Performance How-To
On Christmas Day, while delayed at the Atlanta airport, I wrote a quick tutorial blog on using the vi (very intuitive) editor. In my haste to get on my delayed flight, I ran out of time to share some more important vi "how-to's" with you. So, here's "Part 2" which includes more vi techniques and tricks... icon_smile


COPY and PASTE

I know you really didn't want to retype all your work simply to replicate a masterpiece. While you are in COMMAND Mode (hit the ESC key), position your cursor at the beginning of the line (or lines) that you want to COPY.

Copying in vi is known as "yanking". Knowing this will make it easier for you to remember the Copy command.

To copy (yank) just a single line (the line you are currently on), hit the lowercase y key twice. For example, yy

To copy (yank) multiple lines beginning with the line your cursor is currently positioned on, enter the number of lines you want to copy followed by an uppercase letter Y. So, to copy ten lines you would enter 10Y.

Now you've got one or more lines copied into vi's buffer. Where do you want to paste them?

To Paste, Place, or Put (notice the P's) the copied line(s) somewhere in the file, you will use either the lowercase or uppercase letter P.

First, position your cursor on a line in your file. If you type a lowercase p command, the line or lines will be pasted below the current line. If you type an uppercase P command, the line or lines will be pasted ABOVE the current line.

CHANGING CASE

While in command mode, position your cursor over any alphabetic character in your file and hit the squiggly key (most people call it the tilda character). The ~ is usually located under ESC on most keyboards and you'll probably have to hit SHIFT to access the squiggle.

The squiggle, or tilda, is magic. If a character is currently lowercase, the squiggle will change it to uppercase. If the character under your cursor is currently uppercase, then hitting the squiggle will convert it to lowercase.

You can get kind of crazy and have some fun with this by repeating the Change Case (squiggle/tilda) command a number of times. Remember, most commands can be repeated by typing a number before the command. So, 10000~ would toggle the case of the next ten thousand characters.

OOOOOPS, I DIDN'T MEAN THAT

Did you make a mistake? Don't like the results of the last command you typed? The lowercase u command will Undo the last command entered.

Summary

Between Parts 1 and 2 of this quick vi editor tutorial, you no longer need to fear the UNIX or Linux world if you are coming from DB2 z/OS or Windows. And, welcome to the "Open Systems" world. Glad to have you here.

Our Shameless Marketing Moment

DBI is offering a free educational webinar "TEN SQL Snapshots you MUST run TODAY" on Friday, 21 January, 2pm Central (3pm Eastern, 1pm Mountain, 12pm Pacific, 8pm GMT). Attendees will receive the SOURCE CODE for the SQL Snapshots! For details and the registration link to this free event, visit DBI's EVENTS page.

Our #1 Job is helping you look great!
Our #2 Job is giving you the documentation to prove it!

Contact DBI and find out how our DB2 LUW Performance Solutions can truly help you optimize performance and lower IT costs.

To all of you, I wish everyone a safe, happy, and prosperous 2011!

Cheers, Scott

Printer friendly