Guru Classic: Everybody Likes Shortcuts! Part 1, Navigation
August 14, 2019 Susan Gantner
I wrote the original version of this tip a few years ago but I still find a lot of RPGers aren’t using keyboard shortcuts as much as I think they should be. Since shortcuts can make you so much more productive, I’m re-visiting this topic with a few updates for changes in more recent versions of RDi. It’s also a follow-on to my last Guru Classic tip on RDi keyboard shortcuts.
I’ve seen a particularly sharp increase in the use of RDi (or Rational Developer for i) by RPGers in recent years. I suspect that has a lot to do with the fact that it is the only editor that supports the new V7 all-free-format version of the RPG language. Even among shops that are not planning to make use of free form D specs right away, this limitation seems to have made people realize that the writing is on the wall and that SEU’s day has come and gone.
One way that I gauge the interest in RDi is in the number of requests for my RSE Quick Start Guide and Favorite Keyboard Shortcuts. They are more popular than ever!
It seems that once they get hooked on them, people really like shortcuts, especially when it comes to RDi. So this tip includes details on a couple of handy shortcuts that are not as widely known. In particular this tip will concentrate on shortcuts to help you navigate your way quickly through a source member.
One of the big advantages of using RDi is that all the code is local on your workstation, which can make it faster and easier to find your way around, particularly with large source members.
First, let’s look at the Ctrl+Home and Ctrl+End keys. These simply jump to the top (Home) or to the end (End) of the source. Both of these shortcuts work in many Windows applications, not just RDi. However, RDi adds a nice touch in that it automatically creates a “quick mark” at the line of code where you were when you hit the shortcut key. A quick mark is like a temporary bookmark that you can subsequently jump back to by using the Alt+Q shortcut.
So imagine that you’re editing some old RPG code that uses a number of (shudder) compile-time arrays. One of the reasons I dislike compile-time arrays so much is that the definition of the array is near the top of the source and the data is at the opposite end of the source. In RDi, if I’m positioned on either the definition of the array or on a reference to an element of the array, I can use Ctrl-End to jump to the end of the member to look at the data. Then I use Alt+Q to get immediately back to wherever I was. Of course there are other occasions when jumping to the top or bottom of a member is handy, such as peeking at the standard comment block near the top of a member that many shops include, or when I need to move to the file declarations to make changes there.
There’s a similar navigation tool that I use even more often. When I’m positioned on the name of a subroutine or an internal subprocedure in some RPG logic, I use the F3 key to jump directly to the subroutine or subprocedure code. After I’ve studied the logic there, there is a similar shortcut to get you back where you started (i.e., the EXSR or procedure call). It’s not Alt+Q any more (a change that occurred a few releases ago). To get back after navigating to a routine you now use Alt+Left_Arrow. If you look at the message area at the bottom of the editor after doing F3, a reminder appears to tell you how to get back there. You can also use the combo of Alt+Right_Arrow and Alt+Left_Arrow to bounce back and forth from the routine code and the call to that routine.
It gets even better – F3 can now also be used for jumping to definitions of data items. As with subroutines, position on the name of a variable and press F3 for a quick way to get to the definition of that variable in the program. Again, Alt+Left_Arrow takes you back to the location where you originally pressed F3.
One of the most common questions I get asked when I’ve shown this shortcut to people is “why F3?” And the answer is: I have no idea. It does seem a rather odd shortcut to use for that purpose. I think most of us think “exit” when we think of F3. But it is a very handy shortcut, so give it a try. Even if you must first overcome the fear that it may close your source member!
What is to me the most significant thing about these shortcuts is the fact that they will return you to the point in the code where you were when you decide to look at something else. There are many ways in RDi to navigate to the top or bottom of the code or to the definition of data or a subroutine. But using these shortcuts are the only ways I know of to get yourself quickly back where you were originally. That saves me a ton of time!
As I’ve noted, the Ctrl+Home, Ctrl+End keys automatically set a quick mark for you. It’s also sometimes handy to know how to set a quick mark manually anywhere you want. To do this, simply use Ctrl+Q to set the mark, and as with the shortcuts before, use Alt+Q to return to that spot quickly.
Note that Alt+Q also sets an automatic quick mark at the location where you were. So that means you can use Alt+Q to continually jump back and forth between two different parts of the code as often as you need to.
There is only ever one quick mark available at a time and it is meant for short-term use. If you want to have a way to have multiple spots in the code that you can return to any time, even days later, then you probably want to look into using either Tasks or Bookmarks. These are very similar to quick marks except they can have names or descriptions and you can have as many as you want. They are also retained until you delete them so they can be very useful to mark important parts of the code for longer term purposes. Paul Tuohy wrote a tip on using Tasks and Bookmarks so I’ll leave you to study that topic on your own here.
While on the subject of source navigation, I’d be remiss if I didn’t give a shout out to one of my favorite RDi features: the Outline view. This also allows me to quickly find where fields, data structures, subroutines, and subprocedures are defined and/or referenced in the source member I’m editing. Outline view has been my primary navigational tool for years, so much so that I’ve often commented that I don’t think I could write an RPG program without an Outline. As noted above, however, clicking in the Outline only gets me where I want to go – it won’t automatically return me back to where I was afterward, so I now use F3 as my primary navigation method.
Another tool that I’ve used to help with navigation is filtering. While the Outline gives me a list of every statement where a field is referenced and I can click on each reference to position to them one at a time, I sometimes find it faster to simply filter out all the code except those lines that reference that field. Then I can hone in on the statement that I’m interested in and then view it in context with the rest of the code around it.
There are two ways to filter on a field name (or any other text for that matter, but field or structure names are the ones I use most often). The first is to find the field name somewhere in the source, select it (double click), then right click and choose Selected→Filter selection. You will then see only the statements with that field name. Position to the statement you’re interested in and then choose Show All from the context menu or use the shortcut Ctrl+W. If you just want to peek at the code around it, you can click on the + signs that appear to the left of each line.
The second way to filter on a name is to use the Find/Replace dialog. The shortcut for this is Ctrl+F. Then key the name into the Find box and click the All button to the right. Alternatively, of course, you could also use the Find/Replace dialog to simply position to each use of that field with the Next button or the corresponding Shift+F4 shortcut.
Sometimes you may want to filter the code by change date rather than on a name. This can be particularly helpful if you suspect a recent change to the code may be causing the bug you were just assigned to fix. This is easily done by bringing up the context menu anywhere in the editor and choosing Filter view→Date. The resulting dialog allows you to enter a single date or a date range to search for.
If you prefer to navigate to each line changed within a date timeframe one statement at a time, use Ctrl+Shift+D (search by change date). In addition to finding bugs recently introduced into the code, I’ve worked with shops who find this helpful when doing code reviews.
Wow! Until I wrote this tip, even I didn’t realize how many different ways I use RDi features to navigate through code. I’m sure there are more navigation tricks that I haven’t remembered to include here, probably even some that I haven’t found yet. If I’ve missed out one of your favorites, let me know!
Susan Gantner, an IBM Champion and co-author of the popular Redbook, Who Knew You Could Do That with RPG IV, is one of the top speakers/writers/trainers on IBM i development topics. She is a partner at Partner400 and System i Developer, and she hosts the RPG & DB2 Summit twice per year with partners Jon Paris and Paul Tuohy.
Some additional nodes on F3 and Quick Marks.
* Quick marks you create manually with Alt+Q you can only have one of, but using F3 creates multiple quick marks. So if you are in mainline and F3 on an SR, then another SR, then a procedure call, then a variable definition, then if you use Alt+Left_Arrow multiple times you will go back through that entire history.
* Ctrl-Click on a variable/SR/procedure has the same effect as F3. Personally I find that easier than clicking on the variable name then pressing F3, because where I keep my hand on the keyboard means Ctrl is an easier press than F3.
I knew most of the shortcuts but never really understood how quick marks work, now I’ll give it another try. Ctrl-Shift-D was new to me, I think I may use it in the future.
One extremely helpful shortcut I use when I got lost in my code is Ctrl-J — return to the last code line you changed.