keybinding-mode

Advanced keymap management in Atom

deprint

1,082

6

0.1.3

MIT

GitHub

This package consumes the following services:

keybinding-mode

Travis AppVeyor Dependency Status apm apm

Advanced keymap configuration in Atom

HowTo

  1. Open your keymode configuration with keybinding-mode:open-advanced-keymap.
  2. Configure your keymaps. Bind keymaps to hotkeys (see Hidden Keymaps), etc.
  3. window:reload or keybinding-mode:reload.

There can only be one keymap active at a time. To load a keymap at startup, see Autostart.

Syntax

'Simple Keymap':
  keymap:
    'atom-workspace':
      #...
'.Hidden Keymap':
  keymap:
    'atom-workspace':
      #...
'Include other keymaps': [
  'Simple Keymap'
  '.Hidden Keymap'
  keymap:
    'atom-workspace':
      #...
]
'Include all keymaps ending with -emacs': '~-emacs$'
'Disable keymaps of other packages': '-find-and-replace'
'Disable all keybindings that start with ctrl-k': '-k/^ctrl-k/'
'Move all alt- keybindings to ctrl-k': '-k/^alt-/ctrl-k /'
'!import': ['other-keymap.cson'] # Split your adv. keymap across multiple files
'!autostart': 'Simple Keymap' # Load 'Simple Keymap' at startup

Static Keymaps

'Static Keymap':
  keymap:
    'atom-workspace':
      #...

Static keymaps are objects with one key keymap which contains a custom keymap.

Dynamic Keymaps

'Dynamic Keymap': '-user-packages'

Dynamic keymaps are generated on the fly. If the dynamic keymap begins with +, it adds the keymap. On -, it removes (unset!s) it. The following dynamic keymaps are included in "vanilla keybinding-mode":

+/-user-packages, +/-core-packages and +/-package-name load/remove package keymaps instead of unset!ing them. To force these three modes to return a keymap, use +! and -!.

Regular Expressions

'Matching regular expression': '-k/^ctrl-k/'
'Replacing regular expression': '-k/^ctrl-k/ctrl-x/'

All regular expressions start with + or -, similar to dynamic keymaps. The next character describes the property that we want to match:

Here, / is the separator. If you want to match / in your regular expression, choose a different separator.

The replacement string in substituting regular expressions can contain $1, $2, ... to work with capture groups.

A + substitution adds the replaced keybinding. A - substitution also unset!s the old one.

Combined Filters

'Merge multiple keymaps': ['-k/^ctrl-k/', '-find-and-replace']
'Filter keymaps': [
  [
    '+k/^ctrl-/'
    '-k/shift/'
    '-k/^ctrl-k/^ctrl-m/'
  ]
]
'Combined filters': [
  '-k/^ctrl-k/'
  [
    ['+k/^alt-/', '&', '+c/^editor:/']
    '-k/^alt-/ctrl-k /'
  ]
]

Combined filters have the form [source filters+]:

  1. The parent filter's source is filtered through source.
  2. Every filter filters source separately.
  3. The keymaps from all filters are merged in order and returned.

In Filter keymaps, for example:

The outer array of a mode has a slightly different syntax, [filters+]. If you execute the mode directly, source is implied to be !all ("All keybindings"). If the mode is loaded from another mode, source depends on the position of the include in said other mode.

If you want to chain multiple filters (AND them), use [filter1, '&', filter2, '&', filter3, ...]. If you only want to combine two filters, you can omit the &.

Hidden Keymaps

'.hello': #...
'world': ['.hello']

Visible keymaps (those that don't start with .) have a command associated with them (keybinding-mode:MODE-NAME). You can toggle these keymaps through the command palette or by binding a key to it. Hidden keymaps can only be included by other modes.

Static Keymaps with regular expression

emacs: ['~']

~REGEX includes all static keybinding modes matching REGEX.

~ without a regular expression matches \.?NAME-. In this example, all modes starting with emacs- would be matched. This also includes modes from other packages (that use the service interface) and is a simple way for other packages to provide alternate keymaps (e.g. for emacs users).

Invert Keymaps

'Disable keybindings that do not start with ctrl-k': ['!not', '-k/^ctrl-k/']

['!not', filter] returns all keybindings that did not pass filter. filter cannot be a substituting regular expression.

Import other keymap files

'!import': ['other.cson']

!import loads modes from all file paths in array (relative to the current file).

Autostart

'!autostart': 'emacs'

Activate mode at startup.

Local keymaps

If your project contains a .advanced-keybindings.cson, it loads modes from that file at startup. !autostart in local keymaps override global !autostart.

Service Interface

"providedServices": {
  "keybinding-mode.modes": {
    "versions": {
      "1.0.0": "provideModes"
    }
  }
}
provideModes: ->
  name: 'package-name'
  modes:
    'static-mode': [
      '!all'
      keymap:
        'atom-text-editor':
          #...
    ]
    'dynamic-mode': (op, sobj) ->
      #...

Packages can provide two types of modes:

These modes do not get their own commands, it is up to the user to include them in his advanced keymap.