Thursday, 24 May, 2007

Keyboarding [Part 2] – Power of the Alt Key

Continuing on with the challenges of dropping the mouse in favor of just the keyboard. This is the second and final installment of using the navigation keys, with the assistance of the Ctrl, Shift and Alt keys to give that added little boost, when you need to move around in your code. So far we've cover the basic navigation keys alone, in combination with Ctrl, with Shift and with Ctrl-Shift. We've seen the cursor move, move fast, select text and select text fast. We've also seen it do unexpected events like what you'll get from Ctrl-Shift-Up/Down. Adding the Alt key is like putting the navigation keys on steroids ... well, to an extent. It does bring some interesting features to the table. One thing I have noticed, looking into these key-combinations is that a few of them ... can be just plain confusing. Look beyond what you expect and it will all make [some sort of] sense. We're going to get off to a bit of a slow start, but hang in there, things will pick up and there is at least one gem that you really need to have in your arsenal. First we'll have a look at the just the Alt key and the tricks it will do when used in combination with the navigation keys:
  • Alt-Home, does nothing.
  • Alt-End, does nothing.
  • Alt-PgUp – loops “down” through the tabs in the editor [History to Design to Code] while,
  • Alt-PgDn – loops “up” [Code to Design to History] thought them. These two are a bit of a head scratcher in that ... they don't “really” move the cursor as the other navigation combinations do and, if you consider that in navigating a tabs sequence, moving from the first to the second to the third would be "up" and the other way would be "down". Fortunately, they do loop "through" the tabs so, with only three of them ... it's not a big issue and it is a neat key-combo to have and use. Perhaps considering it as “PgUp cycles through to the left and PgDn to the right” might come close to something more memorable. Moving on to Alt and the Four Arrow Keys we find that; [Pay Attention now ... this is finally getting good!!!]
  • Alt-Down, does nothing, which leaves us with the Code Browsing Trio;
  • Alt-Up, will move the cursor to the declaration of the “token” under the cursor. I've seen several different variations of this definition and this amalgamation of all of them is as close as I can get you. This combination happens to be one of those power keys that you really, “really” need, not only to know, but to clearly understand. A number of the gurus have already described the use of this key-combination fully so I don't really need to. Try a Google search using; Delphi and “Code Browsing” and you'll find you all you need to know and more. Play around with it, you will even find that there is quite a bit more to this key-combination than what's been advertised. Another reason for ducking out of my own explanation here is that, although I've spent quite a bit of time trying to figure out the “if TokenUnderCursor is Foo then Bar else if ...” permutations, in the end, I simply failed miserably at solving the puzzle – so far. If someone else [Nick, Steve ... anyone] wants to take a crack at it [I know I would love to know] I'll certainly link to the blog/article when you're done :)
  • Alt-Left and Alt-Right, will move you back/forward through the “Hotlink History”. As you move around through the code using Alt-Up, Delphi keeps track of where you've been. This is your Hotlink History. Using Alt-Left and/or Alt-Right will allow you to browse through these Hotlinks. You actually have to watch this one ... browse back [Alt-Left] far enough and you end up at the Welcome Page where Atl-Right won't dig you out – you'll have to click on the Forward arrow or select from it's drop-down to get back into the series. There has to more than Alt-Up involved in creating the Hotlink history but, so far, this is as good as it gets. If you're interested in having a look at the Hotlink list, I've found that switching to the “Welcome Page” and drop down either of the listboxes associated with the browser arrow keys [Back/Forward] seems to be where it's kept. Note: Holding down the Alt key and hitting the navigation keys several times may result in special characters being inserted into your code. Releasing the Alt key after every movement seemed to eliminate this in the testing I did. Now let's combine our efforts with the Ctrl and Shift keys to see what hidden treasures will be revealed when using them in combination with Alt and the Navigation keys.
  • Ctrl-Alt-Home and Ctrl-Alt-End will navigate to the first/last method implementation in the current unit respectively and place the cursor at the beginning of the first line following the opening “begin” token.
  • Ctrl-Alt-PgUp and Ctrl-Alt-PgDn do nothing.
  • Ctrl-Alt-Up and Ctrl-Alt-Down will navigate to the previous/next method implementation in the current unit respectively and place the cursor at the beginning of the first line following the opening “begin” token.
  • Ctrl-Alt-Left and Ctrl-Alt-Right do nothing.
  • Shift-Alt-Home and Shift-Alt-End oddly, do exactly the same as Alt-Home and Alt-End, select text to either the beginning or end of the current line respectively.
  • Shift-Alt-PgUp and Shift-Alt-PgDn preform a pretty nifty trick, that I'm sure there's a use for. They will select a column of text either directly above/below respectively of the current selection. The selected column will be equal in height to the number of visible rows in the code window. If there currently is no selected text, a single character to the right of the cursor is selected, as well as the column above it.
  • Shift-Alt-Up and Shift-Alt-Down, will select a column above/below the current selection similar to Shift-Alt-PgUp and Shift-Alt-PgDn, only do it, just as you'd expect, row by row. As above, if there currently is no selected text, a single character to the right of the cursor is selected, as well as the column in the row above/below it.
  • Shift-Alt-Left and Shift-Alt-Right, do exactly the same as Alt-Left and Alt-Right, select the character to either the left or right of the current line respectively.
Well, that about finishes things up with respect to the navigation keys and combinations thereof using them with Ctrl, Shift and Alt. As we've seen there is a lot of power hidden away under your finger tips just waiting for you to harness it. Edit: My explanation of the Shift-Alt Left/Right and Shift-Alt-Up/Down have been edited to correct errors pointed out by Fernando Madruga in the comments below. The errors I made were a result of key-combinations that were high-jacked by one of my IDE add-ins. Sure hope I've got it right this time :)
Many thanks Fernando. Good luck with learning to use what's there and thanks for stopping by, Dave

6 comments:

  1. Sorry to say this but you are nuts! :)

    Are you sure you're using the Classic IDE settings? At least in Delphi 2007 using classic IDE shortcuts Alt-Shift-Down/Up do work! And do as mentioned in the help file: "Moves the cursor down one line and selects the column from the left of the starting cursor position"...

    BTW: welcome to the keyboard users club! ;)

    ReplyDelete
  2. What Delphi version / Keyboard scheme are you using? "Shift-Alt-Left" and "Shift-Alt-Right" don't do as you say in none of the available keyboard definitions I can choose from in Delphi 2007!

    If you're using Delphi 2007, you can get an incomplete list of keyboard shortcuts from here: ms-help://borland.bds5/devcommon/keymappingsdefault_xml.html or here:
    ms-help://borland.bds5/devcommon/keymappingsclassic_xml.html

    Are you sure some of those keyboard shortcuts are not from some IDE plugin?

    ReplyDelete
  3. Fernando, nice catch.

    I've removed all of my IDE add-ins and have gone through the testing again. The post has been edited with the new results. It was a concern from the beginning that one of these tools may have high-jacked one [or more] of the key-combinations. The alarms should have been going off [and probably were] when I was getting the results that I was ... sadly, I ignored them.
    This is my worst nightmare ... making statements that just are not true and posting them for all to see. One of the issues with working alone, no mentor/associate to bounce things off first. I will most definitely proceed with extreme caution from here on in.

    Nuts ... ?!? Well, a bit of a dummy for not doing appropriate "research" certainly couldn't be argued :)

    Again, many thanks.

    ReplyDelete
  4. "Fernando, nice catch."

    Ehehe: I'm a loooong time keyboarder, and whenever I can, I do it from the keyboard... :)

    You are probably ready to see the power of Virtual Machines! :) I keep one with just Win+Delphi 2007 full default install not a comma changed: whenever I need to test something, such as QC bug reports, I just fire it up and test it there! Since I have it configured to restore to a known snapshot on shutdown, it stays clean no matter what I test there!

    This way I can be pretty sure it's not something I changed or some 3rd party component messing up the results!

    Later,
    Madruga

    ReplyDelete
  5. Found it ... the "enhanced" key-bindings I'd mistakenly explained were from ModelMaker Code Explorer and can be switched off with a simple check-box and IDE reboot. Next time :)

    Apologies.

    ReplyDelete
  6. In D2006 Ctrl+Alt+Up and Ctrl+Alt+Down finds the next instance of the word under the cursor. If that is 'procedure' it will find the previes/next procedure, but it works on any string.

    ReplyDelete