Everybody Likes Shortcuts! Part 2, Playing With Blocks
January 27, 2015 Susan Gantner
In my last tip on RSE shortcuts, I talked about shortcuts that help you find your way as you navigate through source members. Eventually, you find the place where you need to work with the code. So in this tip, I’ll concentrate on shortcuts to help with that, and specifically working with blocks of code. First let’s talk about selecting a block of code. There are many ways: You could drag your mouse over the block or hold down the Shift key and use the cursor arrow down key to select the lines for the block. The one I’ve found most useful, however, is the Alt+L shortcut key. Alt-L–used once–selects the current line in the editor. I find this a better way to select a line for copy/paste purposes than mouse or cursor arrow keys because it always se-lects the entire line, not just a portion of it. When pasting a portion of a line in RPG, particularly fixed-format RPG, it can be tricky to position the cursor before the paste to ensure that the columns line up correctly. Using Alt-L followed by Ctrl+C (copy) I can then move to the line where I want to paste it, use the Home key to ensure I’m in the first column of that line and then paste (with Ctrl+V). Note the RDi editor will insert the pasted line before the line where you positioned. There is no need to insert a blank line to accept the pasted code. Alt-L can be even handier when selecting a block of code for copy and paste. Simply use Alt-L on the first line of the block and then Alt-L again on the last line of the block you wish to select. As before use Ctrl+C, Home, and Ctrl+V to insert the lines. Since the lines will be inserted (it will not overlay the code that’s already there), there’s no need to guesstimate the number of blanks lines you’ll need before the paste. Some of you may be wondering why I don’t just use the SEU line commands C/CC and A or B. The answer is that I often do use those. Sometimes it seems easier to use the line commands and other times I find it easier to use the clipboard. But it’s important to know both ways of copying a block of code because the line command option is only available within a single source member. To copy a block of code from one source member to another in RSE, I must use the clipboard and copy/paste. Here’s another use for a block selected via Alt-L. If you’re working in one of those shops where people never delete a line of code but instead comment out the old code, here’s a way to comment a lot of code very quickly. Select a block of RPG code using Alt-L (or any other method you choose) and then use the Ctrl+/ shortcut key to comment out the block of code. The editor will figure out whether the appropriate comment method is * or // and you can customize whether it overlays or shifts the rest of the code by using preferences for the ILE RPG parser. The Ctrl+ shortcut will perform the reverse action, i.e., it will un-comment the selected block of code. Both Ctrl+/ (comment) and Ctrl+ (uncomment) work on individual lines of code as well as blocks. In that case it’s not necessary to select the line. It will just affect the line where your cursor is. Here’s another interesting way to use a selected block in the editor. Have you ever had the situation while editing code with free format-logic that you need to add a level of nesting which requires shifting blocks of the existing code to indent the logic correctly? Next time you need to do that, give this a try. Select the code block to be shifted using Alt+L at the beginning and end of the block. Then use Alt+F8 to shift the entire block one character to the right. Repeat for as many times as needed. Alt+F7 is similar, but shifts the block left. Much more fun than using the old RR and LL line commands! I hope you will find these shortcuts as handy as I have. Feel free to either download a PDF of my Favorite Keyboard Shortcuts card or request a hard copy via email from the System i Developer website. Susan Gantner is half of Partner400, a consulting company focused on education on modern programming and database techniques and tools on the IBM i platform. She is also a founding partner in System i Developer, a consortium of System i educators and hosts of the RPG & DB2 Summit conferences. Susan was a programmer for corporations in Atlanta, Georgia, before joining IBM. During her IBM career, she worked in both the Rochester and Toronto labs, providing technical support and education for application developers. Susan left IBM in 1999 to devote more time to teaching and consulting. Together with Jon Paris, she now runs Partner400, and appears regularly at many technical conferences, including System i Developer’s RPG & DB2 Summit. Send your questions or comments for Susan to Ted Holt via the IT Jungle Contact page. RELATED STORY Everybody Likes Shortcuts! Part 1, Navigation
|