Ken & Mike on the MATLAB Desktop

May 11th, 2007

Setting up keybindings for the Command Window and Editor

For purely historical reasons, the Command Window ships with its keybindings set to “MATLAB Classics (Emacs)”. We used to only have one set of keybindings for the Command Window and we didn’t want to change the behavior that people were used to. The Editor, however, uses the platform’s keybinding set as its default. This often causes confusion when a keybinding doesn’t work in the Command Window like expected. I quite often get requests from customers to hook up a keybinding that is already there. We will probably make changes in this area in a future release, but in the meantime check your keybinding preferences to make sure that they are set they way you want them.

If you are on a Mac, you will probably be much happier if you change the keybindings to the Mac set for the Command Window. Once you do this, command-a will select all and the navigational keystrokes work more like you would expect.

On Windows, if you set your keybindings to the Windows set, you will get the Windows keybindings that you expect. For instance, Ctrl-P will print instead of recalling the previous command history item.

So, if you haven’t done this before, take a look at your keybinding preferences (File->Preferences menuitem) and try changing the keybinding sets to the appropriate platform set and see if you like it:

keybindingprefs.jpg

43 Responses to “Setting up keybindings for the Command Window and Editor”

  1. Michael Seals replied on :

    It would be great to see vim keybindings added to the editor.

  2. C. M. replied on :

    Yes, it would be fantastic. I’m a rookie with matlab. The interface is quite powerful, making necessary to use the matlab editor. Tough task for a vim-addict developer…
    Emacs user were considered, but unfortunately not vim users. Is it something that will be undertaken ?

  3. Kristin replied on :

    At this time we do not have plans to add a new set of keybindings. We are considering other enhancements to the keybindings that will help ease some of this pain in the future.

  4. Ljubomir Josifovski replied on :

    Find it inconvenient that there are ctrl-left/right and ctrl-shift-left/right bindings (move/select word left/right) but not ctrl-backspace (delete word left). Even better, why not allow the user to map key-combination to action in a more flexible way? This is in addition to the existing Windows/Emacs/Mac “presets” - just add an “User” one I guess? Thanks.

  5. Ken replied on :

    Hi Ljubomir,

    Thanks for your feedback. We know key-bindings are not very user-friendly right now. We’re currently doing some significant work on the desktop infrastructure to improve this situation.

    -Ken

  6. Ljubomir Josifovski replied on :

    Thanks. More general note wrt the editor: why not get some known & tested editors in some shape or form in? Why reinvent the wheel? I understand the integration is an issue (the debug mode, etc), but surely there are IDE’s arround to give you some idea what works/doesn’t and where you should put your (always limited) resource. I must say the editor looks like v1. You will put lots of effort and the users will have to wait a few years till you get to v3 which I guess will the first one that will work for most of the people most of the time. I personally change between Matlab’s editor and vim. Fortunatelly “reload-if-changed” and detecting “changed-but-unsaved” seems to work fine in both directions for me, haven’t had a disaster (yet). Just yesterday I had to spent an hour hunting a bug I introduced when I renaming a variable - the editor seems to lack search&replace in a block or I haven’t found it. :-)

  7. Ken replied on :

    Hi Ljubomir,

    Astute observations. Your absolutely right about not reinventing the wheel. My personal philosophy is to use 3rd party libraries whenever possible with the assumption that small focused libraries will be better written and tested than I could hope to do myself.

    The MATLAB Editor does use some foundational libraries, so we certainly haven’t reinvented the wheel. Additionally, users of the MATLAB Desktop have a different workflow than users of traditional IDEs. Thus we must be careful not to unnecessarily constrain users because we’re based on incompatible (from a usability standpoint) technology.

    Your right in that the MATLAB Editors appearance hasn’t changed a whole lot, and I assure you that we’re looking at ways of updating it in a way that also enhances usability. We’re also working on adding some re-factoring capabilities, which will make it much easier to rename variables.

    I appreciate your candor Ljubomir. Its comments and suggestions such as yours that help us understand what customers are looking for.

    -Ken

  8. Matthew Tuttle replied on :

    I realize it has already been said, but I too would like to see a vim key binding added.

  9. Ken replied on :

    Thanks for your two-cents Matt!

  10. Brian replied on :

    It has been said, but it is important to me so I’m adding the comment again. Once you’ve got used to vim you feel as if your fingers have been hacked off when using the matlab editor. On the other hand the commandline debug mode is not as comfortable as it should be (e.g. I always try to repeat e.g. dbstep by pressing return, because thats what I’m used to from gdb), so sometimes you have to use the GUI.

    It would be great if matlab would export some kind of service to enable driving it from within vim. And if additionally the matlab lint would be an external program everything necessary could be accessed from within the comfortable vim ui.

    But if all this is too much to hope for, then at least the most basic vim editing capabilities
    - Vim Two-Mode Interface
    - Vim Navigation
    would already make me feel much more comfortable.

    Brian

  11. Ken replied on :

    Hi Brian,

    Thanks for your feedback - your suggestions are good. We’re doing some significant work in the Editor right now, that may make the things you ask for easier to support (though this is a large scale project and so it won’t be visible for quite a while).

    It certainly makes a difference, when you, the users, convey what’s most important to you. So we do appreciate all these requests and suggestions.

    Thanks,
    -Ken

  12. Mike replied on :

    Brian,

    You can also run M-Lint on a file from the MATLAB command line. It does not give you the nice colors, but it has all the pertinent information.

    http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/mlint.html

  13. Terran replied on :

    First, I should say that I’ve been fairly impressed with the recent Matlab IDEs. I’m a die-hard command-line hacker, and I avoided the Matlab editor for a long time b/c I was much more comfortable with Emacs. Recently, however, I have been swayed and am getting much more into using your editor/debugger environment. Nice going.

    I would second the request for fully user-configurable keybindings. (Even if you have to hide the full configuration fairly deep in prefs to not scare newbies.) I find that I want a sort-of hybrid, Frankenstein’s Monster sort of keybinding that is half Mac and half Emacs. (E.g., my fingers think “splat N” for new file and “splat F” for search, but “ctrl-e” for move-to-end-of-line.)

    Other features that I would find useful in the IDE are:
    - dynamic help for function calls in tooltips attached to mouse hover-over (or even on a quick keybinding), a la Eclipse
    - function call, function argument, and variable completion. Tab completion sort-of gets there, but I find myself continually surprised by what it doesn’t complete.
    - a “go to the declaration of the selected thing” widget. There seems to be one for function names, but not for general variables/arguments. I know that this might be hard b/c of Matlab’s effectively weak typing and lack of declarations (esp. for global vars, which don’t have a clearcut home), but it would be a big help when reading legacy code.
    - Code templates for common idioms, again a la Eclipse. Especially for things I do a lot (like checking numbers, ranges, etc. of function arguments), it would be stellar to be able to fill in the function prototype, hit a key, and have it generate a default set of argument checks that I could then edit down to what I wanted.

  14. Ken replied on :

    Hi Terran,

    All great ideas! You’ll be happy to know that most of them are already in the works.

    Re. Customizable key bindings: We’re working on this. We’re not addressing the larger issue of Vim style key bindings right now, as that would be a much larger scope project (though based on the number of requests, we will certainly discuss it).

    Re. Dynamic help: I think we have the feature you’re looking for - check out Help on Selection. This feature pops up up a light-weight help window when your cursor is on a function and you press F1.

    Re. Better IntelliSense style completion: We’re working on it!

    Re. Better “go to” support: This is actually part of a bigger picture, namely refactoring capabilities. We’re working on this too.

    Re. Code templates: Working on it.

    Thanks for all the great suggestions Terran.
    -Ken

  15. joshua vogelstein replied on :

    the new meditor features makes it a necessary tool for my productivity. a modal text editor with vim keybindings would greatly enhance my productivity even further. thanks for considering :)

  16. Ken replied on :

    Thanks for “weighing-in” Joshua!

    -Ken

  17. Eric replied on :

    VIM!!!

  18. Mary replied on :

    Personally, I’m really tired of typing :w in my Matlab editor and having it result in a “:w” on the screen when I wanted to save. I love some of the Matlab editor features (like cell mode) and as a result I use it instead of vim (which I used to use for all my Matlab coding).

    The problem is my fingers automatically type vim commands, *all the time*. I would love a vim-like editor in Matlab.

  19. David replied on :

    Just adding my $0.02… I really need VIM key bindings. Anyone who has really worked with VIM for any period of time knows how frustrating it is to work with ’simpler’ GUI/mouse based editors. However, the other features in the MATLAB IDE (which are way cool, btw) almost preclude using VIM to edit MATLAB files.

  20. Ken replied on :

    Duly noted. Thanks for the input David.

  21. Bart replied on :

    Please add VI or VIM key bindings as an option in the matlab preferences window. These key bindings are already present in most readline libraries (and often can be accessed by pressing M-C-j).

    EMACS is not the only editor out there! :-)

  22. Mike replied on :

    Bart,

    Thanks for the input. We understand the pain of switching between various programs. Personally, I did something very horrible in IntelliJ because I pressed the Eclipse keybinding. It’s awkward, and we’re working on it, but we can’t even give an estimate on when that will be available.

  23. Bart replied on :

    Thanks Mike, I am looking forward to seeing vi/vim key bindings enabled in a near-future version of MATLAB!

  24. Biswanath Senapati replied on :

    I am using MATLAB tool for our work.
    Now I want to integrate matlab desktop (command window) in our C/C++ program.
    We developed C/C++ GUI and it has interface with the MATLAB.
    Our intention is not use in build MATLAB Desktop, It should come inside of the C/C++ GUI.

    In Linux we have integrated as mentioned above (using matlab -nodesktop).
    But the problem in Windows. There is no such type of command.
    How we can start MATLAB in our C/C++ GUI in WINDOWS XP..?.
    Please let me know any other option available in windows.
    Also I would like to have -nodesktop option in windows..

  25. Scott Hirsch replied on :

    @Biswanath Senapati

    matlab -nodesktop is supported on Windows, too. This page explains how to do it: http://www.mathworks.com/support/solutions/data/1-19ZXU.html

    If it’s not working for you, please contact technical support.

    - scott

  26. Mike replied on :

    Add me to the list of people asking for Vim keybindings.

  27. Barbara replied on :

    Just adding my voice to the requests for vim bindings. Currently, I find myself switching back and forth between the Matlab editor and vim for matlab coding, as the Matlab editor has some great debugging features, but I need vim for any serious editing.

  28. Jody replied on :

    Isn’t the fundamental problem with using vi bindings that vi is a modal editor? How do folks think “:w” will work in a non-modal editor like medit? I’m not trying to say vi is bad, but you’re asking the desktop team to put another mode on top of the editor, and that seems like a lot to expect.

    I’d prefer to see configurable keymaps. This could be relatively arcane, as the kind of folks who want to go whole hog changing keymaps aren’t likely to be put off coding it by hand in a configuration m-file.

  29. yangleecoool replied on :

    It would be great to have vim key bindings in matlab!

  30. Sarah replied on :

    I wanted to second the requests for vim keybindings. I need the debugger flexibility of the matlab editor, but wish I could edit much more fluidly.

    At the very least a “Revert to Saved” button so that I could edit in vim and then instantly refresh in the Matlab editor before running the debugger would help a ton.

  31. Ken replied on :

    Hi Sarah,

    You can have the MATLAB Editor automatically reload a file if that file has been changed externally. Goto:

    Preferences -> Editor/Debugger

    then check the Reload unedited files that have been externally modified checkbox.

    -Ken

  32. Christian Peel replied on :

    What’s the status of the customizable key-bindings that Ken mentions above?

  33. Ken replied on :

    Hi Christian,

    We’re working on it. In fact, this beta feature is in a very mature state right now, so keep your eyes peeled.

    -Ken

  34. Adam replied on :

    another vote for vim style keybindings!

    i know that recreating vim inside the matlab editor would be a pretty huge undertaking. however, i do know that some work has been done so that vim can be “hosted” in ms visual studio. perhaps those same hooks or something similar could be used. (if it were compatible with the visual studio interface, that would probably give you support for a whole bunch of editors for free!) check out vim on windows and the “visvim” extension.

    cheers!

  35. Faraz replied on :

    Another vote for VIM.

  36. Yair Altman replied on :

    For anyone interested in non-standard key bindings, look at my recent submission to the File Exchange called EditorMacro: http://www.mathworks.com/matlabcentral/fileexchange/24615

    EditorMacro enables assigning user-defined macros to keyboard bindings in the Matlab editor. For sample usage look at the FEX page, or one of these webpages:
    http://undocumentedmatlab.com/blog/EditorMacro
    http://undocumentedmatlab.com/blog/non-textual-editor-actions

    Yair Altman

  37. michael replied on :

    Another vote for vim! I’m trying to decide on a software development framework for a university lab, but I am surprised to find that free Python IDE’s, e.g. Wing, allow editing code with vim “behavior” (modal) but MATLAB, which is a very expensive software package, does not. This seems very strange to me. In all the years that MATLAB has existed, why has no vi like option for editing code been implemented?

  38. Stephen replied on :

    Yet another vote for vim keybidings. I understand that it’s difficult because of the modal nature of vim, but as a compromise, including some functionality of vim, and letting the user change the keybindings themselves, would be nice (is it possible to allow simple

    Esc + [letter]

    keybindings?)

    For example, I miss the search feature of vim where you can just type

    *

    (the asterisk) and it will search for the word under the cursor (and highlight all instances).

    Also, deleting a line and putting it into temporary storage (

    dd

    in vim) could be made into a single command In emacs mode, you need to first type

    cntrl+a

    to get to the beginning of the line before you can do

    cntrl+k

    to yank the link. I just want these commands combined!

    But, anyhow, good job on R2009b with the customizable keybindings. I never memorized the cut/copy/paste shortcuts for emacs, so now I can just use the windows keybindings. Very nice. Thanks!

  39. Jonathan replied on :

    Another vote for vi keybindings. It may be a larger undertaking, but compare it to the sum(frustration(all_vi_users)).

  40. Jonathan replied on :

    Plus is it really that hard? I think tcsh.exe from the cygwin distribution had both vi and emacs bindings over 10 years ago.

  41. Ken replied on :

    Hi Jonathan,

    It’s not quite that simple. Vi is more than just the keybindings — its a modal way to edit your text (insert mode and command mode). That modality is integral to the Vi experience, and is not a simple thing to retro-fit on the MATLAB Editor.

    -Ken

  42. Juan Nunez-Iglesias replied on :

    Ken,

    Thanks for keeping the thread updated and responding to people’s concerns directly. It makes a huge difference to know that you are being heard, even if things are slow to change.

    Having said that… Where is VIM??? ;)

    Do you at least have an ETA yet? I’ve actually only just started with Matlab and have been typing “Esc-DD” ALL. DAY. LONG.

    Thank you!

  43. James replied on :

    I’d like to umpteenth the vim keybindings.

    Not reinventing the wheel came up, why not incorporate readline or libedit? Then we’d get emacs, vim, and customization for free.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • DP: Hi i have a problem with ezplot3, i want to plot more than i curve in the same graph but hold on command...
  • Ken: Hi Arsalan, Unfortunately there is no way to get the new Editor API in older versions of MATLAB. -Ken
  • Arsalan: Hi, I am very excited about the MATLAB API for editor because right now i am working on a project and i need...
  • Johannes: Since I started using matlab-emacs some days ago I never experienced Emacslink. But I experienced some...
  • Francisco J. Beron-Vera: Hi all, I have recently learned about ViEmu (http://www.vimemu.c om) which, for Vi/Vim...
  • OysterEngineer: When I first learned of the Publish feature in MatLab, I thought it might be useful to help to...
  • Ken: Hi Herve, I’m not quite sure what you mean by “stand-alone&# 8221; mode? -Ken
  • Herve: I wonder when the publish fonction will be supported in standalone mode.
  • Mike: Ravi, What you described should work as far I understand it. Please follow up with technical support. With a...
  • Mike: @Daniel, Thanks for that note.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.