GExperts: Copy or Cut the Identifier or Line with Ctrl+C and Ctrl+X

A feature request that has been open since 2019 (#91 One Key Cut/Copy) asked for something the long dead CodeRush for Delphi (archive.org) used to offer: with nothing selected, Ctrl+C copies the identifier at the cursor and Ctrl+X cuts it. GExperts can do that now, and it can also do what Visual Studio does, copying or cutting the whole line instead.

It is an option of the Editor Enhancements expert. Open the GExperts configuration, select Editor Enhancements and click Configure. The group “Ctrl+C / Ctrl+X without a selection” decides what these keys take when nothing is selected:

  • Do nothing (IDE default): the keys behave as they always did. This is the default.
  • Copy / cut the identifier at the cursor: the CodeRush behaviour the feature request asked for.
  • Copy / cut the current line: the whole line including its line break, like in Visual Studio. On the last line of a file, which has no line break, it takes the text up to the end of the line.

The Code Editor Enhancements Configuration dialog with the new group Ctrl+C / Ctrl+X without a selection

With a selection, the keys work as usual. If the cursor is not on an identifier, the IDE gets the key as if GExperts were not there. Copying leaves the cursor where it was, and a cut can be undone with Ctrl+Z like any other edit. The Editor Enhancements expert must be enabled for any of this to work.

If you have assigned Ctrl+C or Ctrl+X as the keyboard shortcut of a GExperts expert, that shortcut takes precedence, so the option will not seem to do anything for that key.

This enhancement works only for Delphi 7 or later. Depending on how the keys are registered with the IDE, Delphi 6 either never passes Ctrl+C to a plugin or crashes when it is closed, so the option is not available there.

The implementation is in GX_EditorEnhancements.pas.

As usual, if you want to try this before the next official release, you can compile your own DLL.

Discussion about this in the corresponding post in the international Delphi Praxis forum.