Sublime Text - Key Bindings

Key bindings in Sublime Text helps a user to process and map the sequences of key presses to actions. They are defined in the JSON format and are stored in .sublime-keymap files.

For better integration, it is important to keep separate key map files for Linux, OSX and Windows. Key maps of the corresponding platform will be loaded in the Sublime Text editor.

A user can open the keymap file or default key bindings using the option Preferences → Key Bindings.

Key Bindings in Sublime Text1

Key bindings in Sublime Text2

The following example shows how to perform key bindings in Windows −

   { "keys": ["ctrl+shift+n"], "command": "new_window" },
   { "keys": ["ctrl+shift+w"], "command": "close_window" }

Defining Key Bindings

Sublime Text editor includes an option to define a key map. The key bindings defined in the file .sublime-keymap includes all the key value combinations.

Defining Key Bindings

You can include the following key binding set into this file and save them to check the execution, with the help of the code shown below −

      "keys": ["super+alt+;"], "command": "run_macro_file",
      {"file": "Packages/User/semicolon.sublime-macro"} 

Here super is the Winkey in Windows or Linux, and a command on OSX operating system. Note that this code will run the macro that is located in Packages/User and is named semicolon.sublime-macro on pressing the Super+Alt+ keys.