View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
KeyBindings - Alter Matlab Editor key bindings

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 6.56 KB File ID: #25089 Version: 1.1
image thumbnail

KeyBindings - Alter Matlab Editor key bindings



20 Aug 2009 (Updated )

KeyBindings alters Matlab Editor's keyboard shortcuts.

| Watch this File

File Information

KeyBindings is inspired by EditorMacro (, although these two functions have slightly different focus. KeyBindings focuses on altering built-in shortcuts of the Editor, whereas EditorMacro provides also shortcuts for custom matlab functions and code templates.

Main motivation for me to write this function and for you to use it is better support for docked editor window and support for multi-key shortcuts.

KeyBindings uses different approach to modify shortcuts than EditorMacro. Main benefits of this are:
 + Custom shortcuts don't get reseted when editor is docked.
 + Supports multi-key shortcuts.
 + Filetype change does not reset custom shortcuts.
Unfortunately, this approach does not provide "perfect" solution. Main drawbacks are:
  - Supports only built-in (java) actions, i.e. it is not possible to bind shortcut to you own matlab-function.
  - All open documents have to be reloaded after shortcuts are modified (function does that automatically).
  - Requires at least Matlab version R2007b.
However, the good thing is that the user can cherry pick best features of KeyBindings and EditorMacro. These two functions should work nicely together.

     bindingsList = KeyBindings(keystroke, actionID)

KEYSTROKE is a string representation of the keyboard combination. Special modifiers (Alt, Ctrl or Control, Shift, Meta, AltGraph) are recognized and should be separated with a space, dash (-) or plus (+). Multi-key shortcuts can be created by separating keystrokes with comma (,). At least one of the modifiers should be specified, otherwise very weird things will happen...
For a full list of supported keystrokes, see:
If KEYSTROKE was already defined, then it will be updated (overridden).
In addition to java keystroke representation the keystroke can be one of the following code words:
         Save - Store current key bindings to file under $prefdir.
         Load - Read previously saved key bindings from file.

ACTIONID should be name of one of the Matlab's build-in actions. Available actions with their descriptions and current key bindings are listed when no input arguments are given.

After any modification to key bindings all open documents are reloaded to update shortcuts. Thus all documents have to be saved before modifying key bindings.
   - Saving and reading key bindings to file works only in R2009a. Otherwise this should work with R2007b+.
   - It is not possible to assing keystrokes to text templates or custom Matlab functions, only built-in actions are supported.

     % List current key bindings
     % Add new key binding
     KeyBindings('Shift Ctrl M','show-mlint-report')
     % Alter multiple key bindings at once
     KeyBindings({'Ctrl B,B','Ctrl B,N','Ctrl B,P'},...
     % Remove keybinding

     This code heavily relies on undocumented and unsupported Matlab functionality. Use at your own risk!


Editor Macro Assign A Macro To A Keyboard Key Stroke In The Matlab Editor And Command Window inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
21 Aug 2009 1.1

Emphasized relationship to EditorMacro.

Contact us