Wednesday, November 09, 2016

Editing PL/SQL with Sublime Text 3 and Multiple Cursors

I'm a recent convert to the Sublime Text 3 editor, having managed for many years with TextPad.  One of the most useful features for me is multiple cursors, which allow you to make the same change to multiple lines at once.

For example, it comes in very handy for quickly adding an API over a table (assuming you don't have a nice utility to generate one for you already):

1. Describe the table and copy the column definitions into Sublime Text, deleting the first few lines:


2. Select all text and change to lowercase (because that's the standard):


3. Set up multiple cursors just before each column name (start on first and use Ctrl+Alt+Down):


4. Move all cursors to end of column name using Ctrl+Right:


5. Select to end of line (Shift+End):


6. Delete the selection:



7. Type " in ":



8. Return to start of all lines (Home) then add ", p_":



9. Use Ctrl+Shift+Right to select the column names:


... then Ctrl+C to copy them.

10 Move to end of lines (End) and paste (Ctrl+V):


11. Type "%type":


12. Realise that at step 7 you forgot to put "emp." after " in ", go back and add it:


(Yes I did forget, and didn't fancy re-creating all the screenshots!)

13. According to taste, use Abacus add-on tool to reformat (Ctrl+Alt+]):


14. Add more code and tweak:


15. Use similar techniques to complete the insert statement by copying and modifying the parameter list twice:



That looks like a lot of steps, but in reality it can all be done in about 10 seconds once you are familiar with the technique.

It took me a few weeks to feel comfortable with it, but now I feel more productive than ever when writing PL/SQL code.

No comments: