Skip to content

Instantly share code, notes, and snippets.

@Ultra-Instinct-05
Last active April 19, 2023 16:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ultra-Instinct-05/e1ca9a4d48641cc6c0af46fec0010611 to your computer and use it in GitHub Desktop.
Save Ultra-Instinct-05/e1ca9a4d48641cc6c0af46fec0010611 to your computer and use it in GitHub Desktop.
All you need to know about Sublime mousemap files.

In case of Sublime Text, the mouse actions are configured by what are known as mousemap files (that have a file extension of .sublime-mousemap). You can have generally 2 variants of these files :-

  • Default.sublime-mousemap: This will define mouse actions for any platform.
  • Default ($platform).sublime-mousemap: This will define mouse actions for a specific platform, where $platform is any one of Windows, Linux or OSX depending on your operating system.

You can view the default shipped mousemap files by using View Package File from the command palette and searching for mousemap.

In order to define your own mouse actions (or override any existing actions), you have to create a file by the name of Default.sublime-mousemap in the User directory (to get to this directory, select Preferences -> Browse Packages ... from the main menu) for platform independent override (or Default ($platform).sublime-mousemap for platform dependent overrides depending on your OS).

Once that's done, here is some basic knowledge about mousemap files (Note that there is no official or community documentation about mousemap files so everything is based on experimentation and what the dev's have said about such files).

Here are the meaning of some keys in mousemap files :-

  • button: This defines the name of the button. For example, button1 refers to the left mouse button, button2 defines the right mouse button, the scroll wheel defines button3. Similarly, you can have button4. button5 etc. I am not sure how many such button names actually exist. Also for the scroll wheel, you have scroll_up for upward scroll movement & scroll_down for the opposite behavior.

  • modifiers: This is a list of modifier keys like ctrl, alt etc. For example, ["alt"], ["ctrl", "alt"]. When you define a modifier list, all the modifier keys listed should be pressed simultaneously and then pressing/releasing the corresponding button triggers some action.

  • command: This defines the command to be executed when the corresponding button is released after being pressed. If this command takes any arguments, you can have an args key for it.

  • press_command: This defines the command to be executed when the corresponding button is pressed. If this command takes any arguments, you can have a press_args key for it.

  • count: The number of times you have to press the corresponding button to trigger the action (by action, I mean execute the corresponding command/press_command)

NOTE: You can define both command and press_command if you wanted to.

Let's look at some examples :-

File name :- User/Default.sublime-mousemap

[
    {
        "button": "button2",
        "modifiers": [],
        "press_command": "echo",
        "press_args": {
            "message": "I am pressed"
        },
        "command": "echo",
        "args": {
            "message": "I am released"
        },
    }
]

Here, the right button (button2) is bound to the built in echo command. If you now right click, the default behavior would have been actually the opening of the context menu, but now we have overriden that behavior and now you can see the corresponding messages {'message': 'I am pressed'} or {'message': 'I am released'} in the console based on whether you have pressed or released after pressing.

For your case, you can have something like the following :-

[
    {
        "button": "button1",
        "modifiers": ["alt", "ctrl", "shift"],
        "press_command": "undo",
    }   
]

Now, when you now press button1 (while holding down alt, ctrl, shift simultaneously), the undo command should be executed. You can set modifiers to an empty list if you don't want that.

If you want to disable any button actions, just use the noop command.

Example :-

[
    {
        "button": "button1",
        "modifiers": [],
        "press_command": "noop",
    }   
]

This will disable button1 and now you can't drag select anymore ;-) So be careful.

Note: This is a slightly modified version of my answer on this StackOverflow answer on mousemap files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment