Search code examples
intellij-ideapluginsintellij-plugin

How can I create a special character shortcut for an IntelliJ plugin?


I would like to attach the shortcut ctrl + [ to an action in an IntelliJ plugin I'm writing.

For ctrl plus any letter, this works. However, for a square bracket, this doesn't seem to work. I have tried escpaing using \[.

For example, this doesn't work:

<action id="DoTheThingAction" class="DoTheThingAction" text="Do It" description="Does The Thing">
    <keyboard-shortcut first-keystroke="ctrl \[" keymap="$default" />
</action>

While this works:

<action id="DoTheThingAction" class="DoTheThingAction" text="Do It" description="Does The Thing">
    <keyboard-shortcut first-keystroke="ctrl w" keymap="$default" />
</action>

Do I need to do anything special to create a shortcut for a special character like "["?


Solution

  • You can't use [ or \[ directly. You need to use OPEN_BRACKET.

    For example, this works:

    <action id="DoTheThingAction" class="DoTheThingAction" text="Do It" description="Does The Thing">
        <keyboard-shortcut first-keystroke="ctrl OPEN_BRACKET" keymap="$default" />
    </action>