How to assign custom key bindings to scripts


Beginning with Geany version 0.14, it is now possible to integrate plugin key bindings with Geany's built-in preferences system.   This allows for much easier configuration, and also helps to resolve conflicts between the editor's bindings and the bindings associated with plugins.

To use the new method, you simply create a plain text file named "hotkeys.cfg" and place it your /plugins/geanylua/ folder.   In this file you will list any scripts that you want to configure keybindings for.   The scripts should be listed one per line and may be specified either by using an absolute path, or with a path relative to your /plugins/geanylua/ folder.

After reloading the plugin (or restarting Geany) the scripts will appear in Geany's   Edit->Preferences->Keybindings   dialog.   The names appearing in the dialog are derived from the filenames in a manner similar to the way menu items are created from filenames.


(The old way)

Important: The technique described below has been deprecated in favor of Geany's built-in keybinding API. It is still working for now, however you are strongly urged to convert your scripts over to the new method.   The reference below is provided mainly for historical reasons...

Before we begin, it is assumed that you are comfortable with your current keybindings in the editor itself. If you are the sort who likes to tweak your editor keybindings on a daily basis, adding script keybindings into the mix will likely be an exercise in frustration!  This is because there is absolutely no coordinated way to detect conflicts between the Geany keybindings and script keybindings, or even between the individual scripts.  So you are the only one responsible to insure that such conflicts don't occur, or at least that they don't cause you any major problems.

The syntax for enabling a keybinding is quite simple, but it must be the very first line in the script file. The line should begin with a double dash (the standard single-line Lua comment marker) followed by a space and the string  @ACCEL@  followed by another space and then the accelerator specification in standard GTK syntax.

For example, to launch a script by pressing the keys  [Ctrl]  [Shift]  [J]  you could write this as the first line of your script:

-- @ACCEL@ <Control><Shift>j

Note that such tags are scanned once only when the plugin is loaded, so any changes require reloading the plugin before the change will take effect.   The plugin can be reloaded either by restarting Geany, or by toggling it OFF/ON via Geany's Plugin Manager, or by calling the rescan() function from inside a script.