Thursday, December 30, 2010

Tips for using vi editor

There are several places online where you can find a list of shortcuts of vi commands. If you are a user of vi, I recommend printing out a copy of the shortcuts and keeping them near your computer. For this blog post I will not provide a list shortcuts, I will discuss a few of the lesser known shortcuts that I use frequently.

I like to use vi to help create one-off scripts to help accomplish tasks. For example, assume you are given a list of 80 tables to truncate. You have a list of table names, but that is all. Using vi, you can perform the following steps to create a script.

Assuming your database is running on a Linux/UNIX server, log into that server as a user that can sqlplus into the database. Use vi to create an SQL file. Paste the list of table names into the file. Now you can do the following to change the line
          employee
into the SQL command 
          truncate table employee;

Replace the begining of the line with "truncate table " and replace the end of the line with ";". After those changes you will have altered a list of tables into a list of SQL commands. To change the beginning of the line you can use the vi command:
          :g/^/s//truncate table /g
To change the end of line you can use
          :g/$/s//;
The beginning of the line is represented by "^" while the end of line is "$". You can use the replace command to replace any text. Many people are not aware of using the end of line and start of line characters in this way. This trick can allow you to quickly create scripts to accomplish many different tasks.

Other vi commands I use frequently include
"." - this will repeat the command you have just run
"/" and "n" - this will search for a string, pressing "n" will search for next instance of the string.
"yy" and "p" - this will yank a line of text, the "p" will paste the text where at your cursor location.


What are some of your favorite vi tips and tricks?

Thursday, December 23, 2010

New Job - New Blog

I am proud to announce that starting in January 2011 I will be working as a Senior Performance Consultant at Hotsos. As a result this change I decided to create a new blog. This blog will be centered upon topics I encounter with my new career of assisting people with challenging performance issues.

This is an exciting change for me. I am not new to blogging, for the past year I have been an active blogger on the FieldAppsDBA blog site with my friends and colleagues. My older posts can still be found on that site. This new site will focus more on performance items and other topics related to my new position.

I hope to provide some useful information on this site. I appreciate your feedback going forward.

Thanks
Paul