Work faster in Delphi XE8 by using Castalia’s keyboard shortcuts


The new Delphi XE8 includes Castalia for easier code navigation and refactorings. The Castalia refactorings however are still separate from the ‘native Delphi’ refactorings and they partly overlap in functionality. They both have their pros and cons. A definite pro for Castalia is that most of the refactorings can be done ‘inline’, that is, there is no modal dialog involved and some way or another, most of your changes can be done directly in your code editor.

Well, no dialogs is nice, but that only improves your productivity if you do not still need your mouse to trigger the refactoring. That means I have a couple of new keyboard shortcuts to start memorizing! Unfortunately, Castalia is not very helpful with that. There are no visual clues anywhere in its (admittedly nicely unobtrusive) editor toolbar, nor in the menus.

Castalia bar docked to the top of Delphi code editor window

The Castalia bar in the Delphi editor window

You have to dig deep in the help files to even find them, or browse to embarcadero’s docwiki.

Embarcadero does a better job for the regular refactorings, although not always consistent, by showing shortcut keys in the Refactor context menu:

Delphi's own Refactor menu

Delphi’s own Refactor menu

Until they come around to fix that omission in XE 8 update 1 😉 to help you and me learning these shortcuts, here are the Castalia keys, which I grabbed from that docwiki mentioned above. Unfortunately, a lot of them require chords, but I’m guessing there are so much shortcut keys in use already, that they were running out of alphabet letters.

  • Ctrl-Alt-N + Ctrl-Alt-U | Displays a list of all the units that the current unit uses. This list is a part of the Navigation Toolbar.
  • Ctrl-Alt-N + Ctrl-Alt-S | Displays a list of of sections of the unit. This list is a part of the Navigation Toolbar.
  • Ctrl-Alt-N + Ctrl-Alt-T | Displays the names of all the declared types in the current unit. This list is a part of the Navigation Toolbar.
  • Ctrl-Alt-N + Ctrl-Alt-P | Displays the names of all the procedures and functions of the current unit. This list is a part of the Navigation Toolbar.
  • Ctrl-Alt-N + Ctrl-Alt-F | Open the Smart Symbol Search.
  • Ctrl-K + G | Drops a bookmark.
  • Ctrl-Q + G | Picks up a bookmark.
  • Ctrl-Q + Ctrl + G | Swaps bookmarks.
  • Ctrl-Shift-Alt-P | Synchronizes the interface and implementation copies of your function prototypes.
  • Ctrl-Alt-Shift-R | Opens a popup at cursor location with available Castalia refactoring actions.
  • Ctrl-Alt-J | Selects the identifier under the cursor.

On a day-to-day basis, I would probably use the navigate to procedure / function (Ctrl-Alt-N, P) the most, but as a heavy Visual Studio + ReSharper user, I have grown very, very accustomed to the Alt+\ (backslash) key combination, which I have mapped to the Structure View Search from Andreas Hausladen’s great DDevExtensions tool (Really, every serious Delphi developer should install his DDevExtensions and IDE Fix Pack per default). This accomplishes largely the same goal, and requires a lot less fingers for that.

I haven’t really had a chance to play around with the smart symbol search (Ctrl-Alt-N, F) yet, but it looks very powerful.

Synchronizing the interface and implementation copies of the procedure/function prototype (Ctrl-Shift-Alt-P) is a really nice feature for which I have made a plea before. Now it is finally here! (Perhaps it was available in Castalia all along, but I haven’t used Castalia since the days of Delphi 2005 or so.) Needless to say I am very happy with this feature.

Tip of the day! One feature that is probably underestimated until you’ve grown accustomed to it, is Selection expansion by using Ctrl-Alt-J repeatedly. At first press, it selects the identifier the cursor is currently on. But if you then press it again, the selection is automatically expanded to the enclosing code block, and that block’s enclosing block, and again, ever expanding your selection to a larger piece of code, but always neatly tucked in between matching brace or begin/end pairs. Try it. It is of great value, especially if combined with the Surround With refactoring, to quickly build an if-statement around a block of code, for example, without having to manually select the start and end of that block. Or just press “(” to put brackets around the selection. Again, I’ve been using ReSharper’s equivalent for years and wouldn’t want to live without it.

But the Refactorings menu is what this was all about from the start. The menu is available by using Ctrl-Shift-Alt-R. This shows a context sensitive menu with all available refactorings for that piece of code. You can use the underlined letter to select your desired refactoring from the menu. Unfortunately, for some of these option, the letter may change, depending on which options you have available, so you need to look and cannot just memorize them — although the Surround with letters appear to be consistent. These are your options:

  • Rename Variable
  • Rename Parameter
  • Inline Temporary Variable
  • Introduce Explaining Variable
  • Split Temporary Variable
  • Remove Unused Variables
  • Eliminate ‘with’
  • Rename Method
  • Extract Method
  • Add Parameter
  • Rename Class
  • Move Class
  • Rename Field
  • Rename Property
  • Surround with
    • Begin..end
    • If then (+ begin .. end if needed)
    • Else
    • For
    • While
    • Repeat .. until
    • Try .. except
    • Try .. finally
    • IFDEF
    • IFNDEF
    • REGION

Good luck and happy coding!

Now, if someone would implement Ctrl-Tabbing in MRU order and the ability to use the Tab key for Autocompletion in XE9, Delphi would be almost perfect. 🙂

Over Shiftkey
I am Maarten, owner of and chief software developer for Shiftkey software development from The Netherlands. I will be writing mainly about things I run into when programming in C# or Delphi.

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

%d bloggers liken dit: