Fleet logo

Fleet

More Than a Code Editor

Development News Plugins

Fleet Plugins – Now With Сustom Keymaps

About a month ago, we launched a mechanism for publishing your color theme as a plugin. With the recent updates, we are extending Fleet plugin applicability even further by allowing you to publish your custom keymaps. You can now map Fleet actions to specific key combinations to streamline your development experience and share the resulting keymap with others.

Customizing keyboard shortcuts

Keyboard shortcuts can significantly boost your productivity as a software developer, but they can also slow you down if they’re not the shortcuts you’re used to. Unfortunately, there’s no one-size-fits-all solution. We put much effort into creating Fleet’s default keymap – we wanted it to respect the system defaults, have familiar shortcuts from other apps like Cmd/Ctrl+K, and be as lightweight as possible to give users the freedom to add their own shortcuts without creating conflicts. However, we understand that it might not be to everyone’s liking. So, we made several customization options available.

First, we added several other keymap options that might work better for you. To switch between them, go to the customization menu by clicking the gear icon in the top-right corner of your Fleet window:

The Keymap dialog allows you to select your preferred keymap:

Second, we allow keymap customization in the Keymap view (it can be launched by the Help | Keymap menu item or the Edit Keymap… action):

The idea behind keymap customization is as follows: 

  • There’s a long list of actions available in Fleet.
  • You can select any action and then replace the assigned shortcut, remove it, or add a new one.
  • It’s possible to restore the default shortcuts (those originally defined in your selected keymap).

Fleet stores your customizations in the user.json file, for example:

{
  "keymap": [
	{
		"key": "shift-cmd-s",
		"action": "show-file-symbols"
	},
	{
		"key": "shift-ctrl-a",
		"action": "toggle-distraction-free-mode"
	},
	{
		"key": "ctrl-o",
		"action": "-open-in"
	}
  ]
}

The keymap array in this example lists all the assignments that differ from the keymap currently selected in Fleet. Let’s call it a delta keymap. For every shortcut assignment, we specify a key and an action ID. Removing a default shortcut is expressed as an action ID with the leading ‘-’ symbol (for example, -open-in). Adding several shortcuts for a single action can be expressed by adding several key/action pairs. Fleet supports viewing and editing this delta keymap JSON file directly via the Edit Keymap in JSON File… action.

If you’ve heavily customized your keymap and think it makes you more productive, you might want to share it with others. Let’s see how you can publish your keymap as a Fleet plugin.

Publishing custom keymap as a Fleet plugin

Like theme plugins, we start packaging a custom keymap by creating a new project from the dedicated keymap plugin template on GitHub. Three things need to be adjusted in the project.

First, you must put a keymap JSON file with a complete list of assigned shortcuts in the my-keymap-plugin/frontendImpl/src/jvmMain/resources/ folder. The easiest way to build such a file is to manually merge the default Fleet keymap (my-custom-keymap.json in the template) with your customizations (the delta keymap) in user.json. There’s one caveat, though. Delta keymap is used for the current operating system, but a complete keymap JSON file is supposed to be useful across different OSes. You can use the ”win”, “mac”, or “linux” key values to set shortcuts specific to the respective operating system. The value of the ”key” field serves as a fallback option. Use definitions in my-custom-keymap.json as an example.

Let’s call this new complete keymap file super-productive.json.

Second, you need to register your keymap as a contribution of your plugin in the my-keymap-plugin/frontendImpl/src/jvmMain/kotlin/fleet/sample/frontendImpl/MyKeymapPlugin.kt file:

package fleet.sample.frontendImpl

import fleet.frontend.keymap.KeymapId
import fleet.frontend.keymap.registerKeymap
import fleet.kernel.plugins.ContributionScope
import fleet.kernel.plugins.Plugin
import fleet.kernel.plugins.PluginScope

class MyKeymapPlugin : Plugin<Unit> {

    companion object : Plugin.Key<Unit>

    override val key: Plugin.Key<Unit> = MyKeymapPlugin

    override fun ContributionScope.load(pluginScope: PluginScope) {
        registerKeymap(
            id = KeymapId("super-productive"), 
            presentableName = "Fleet Super Productive")
    }
}

The keymap ID must be the same as the name of the keymap JSON file (without an extension).

Third, we need to configure the plugin itself. The plugin should have a unique id, a readable name, and a description. The name and the description are visible both on Marketplace and in Fleet’s Plugins view (use the Plugins… action to open it). These parameters are set in the my-keymap-plugin/build.gradle.kts file, for example:

plugins {
	base
	alias(libs.plugins.fleet.plugin)
}

version = "0.1.0"

fleetPlugin {
	id = "pro.bravit.super.keymap"
	metadata {
		readableName = "Fleet Super Productive"
		description = "Super productive keymap for Fleet"
	}
	fleetRuntime {
		version = libs.versions.fleet.runtime
	}
}

Once we are done editing the files, we can launch Fleet with the plugin in development by opening the Run dialog and choosing the Run Fleet with local plugin run configuration. The Fleet instance will be launched after a bit of compilation and will have our keymap available in the Select Keymap… dialog:

We can also check out the Plugins view to make sure that the plugin has been loaded:

While experimenting with your new keymap, you can get your changes as a delta keymap (as described in the previous section) and then transfer them to the complete keymap JSON file. Note that any changes you make to your complete keymap JSON file now won’t be immediately visible in the running Fleet instance. You need to restart Fleet with the Run Fleet with local plugin run configuration selected in order for your changes to take effect.

Once you finish editing and testing your keymap, please follow the instructions from the documentation to publish your new keymap plugin to JetBrains Marketplace. The Marketplace team will check the uploaded plugin, and following their approval, it will become available for anyone to install from the Plugins view in Fleet:

Conclusion

We now allow you to publish your custom color themes and keymaps as Fleet plugins. Some users have already done so. But this is just the beginning. You can do much more to customize Fleet’s behavior with plugins. The road ahead is long and full of possibilities.

Stay with us on this journey!

image description

Discover more