Sort selection

One common and convenient use case of the 'Send selection to' feature is to sort a selection of lines alphabetically.

To do so, simply a custom command to use the sort command line utility. Open the corresponding dialog by using the Edit→Format→Send Selection→Set Custom Commands menu item.

Here we used sort and sort -u, the latter one to sort lines uniquely which means that multiple occurrences of the same line will be removed.

After configuration is done, you can simply sort selected lines by using Edit→Format→Send Selection→sort

Example text before:

2015-05-12 some text
2015-03-04 and some more text
2015-02-04 some other text
2015-03-04 some text

After using the corresponding menu item (or the keyboard shortcut Ctrl-1) the selection will change to:

2015-02-04 some other text
2015-03-04 and some more text
2015-03-04 some text
2015-05-12 some text

Please note, Geany automatically defines the keyboard shortcuts Ctrl-1, Ctrl-2 and Ctrl-3 to the first three items in the configuration dialog. Further items currently cannot be executed by keyboard shortcuts.

More details can be found in Geany's manual at http://www.geany.org/manual/#sending-text-through-custom-commands.

Configuration on Windows

As usual, things are a bit different on Windows. The first pitfall is that there is also a sort utility available, provided by Windows itself. However, it doesn't work together with Geany. But the UnxUtils project provides a port of the Unix sort command line utility which can be used. You need to download the UnxUtils package from http://sourceforge.net/projects/unxutils/files/latest/download and extract the ZIP archive to a location of your choice.

In the Set Custom Commands dialog, specify the full path to the included sort.exe, e.g. c:/utils/usr/local/wbin/sort.exe (assuming you extracted the ZIP archive to c:\utils).

You might notice that we used forward slashes here instead of Windows like backslashes. This is because normal backslashes won't work here though double backslashes would work alternatively.

The green and red icons left to the path text field indicate whether Geany could find and use the entered command.

Print/export