Search code examples
textmatetextmate2

TextMate 2 Escape key: how to disable next completion and previous completion


By default, pressing Esc in TextMate cycles through possible completions (in addition to closing dialog boxes), which can put unwanted characters in your document, especially if you are used to Esc being a safe key to hit in most text editors. (In fact, in a lot of IDEs, pressing Esc a lot is necessary to close auto-completion popups so the up and down arrow keys work.)

How do I disable this behavior, so in normal text editing, the Esc key does nothing, but closing dialogs still works as expected?


Solution

  • What works

    Based on a comment from @matt I found that I can do what I need by overriding the default key binding, as mentioned here, https://manual.macromates.com/en/key_bindings.html :

    In addition TextMate has a /path/‍to/‍TextMate.app/‍Contents/‍Resources/‍KeyBindings.dict file with some extra key bindings which are specific to TextMate (and thus not appropriate to put in the per user global key bindings file). You can copy this file to ~/Library/‍Application Support/‍TextMate and edit it, this will then take precedence over the bundled file.

    I edited the file and took out the line with nextCompletion, assigned to shift+Esc ($\033) and assigned both Esc and shift+Esc to call noop

    "\033"     = "noop:";
    "$\033"    = "noop:";
    

    I learned about the existence of the noop selector here:

    After quitting and relaunching TextMate Esc now does nothing except close dialogs.

    (Apparently to change this one setting, you need to know Objective-C to recognize selector strings, (and assembly which has 'nop') so you can guess that there should be a noop selector. And you need to know octal, so you recognize the Escape key as 033 = 27.)


    Things I tried that failed

    EDIT: for reference for people wondering how it can take 90 minutes to change one little setting.

    I found this paragraph in the manual, at the end of section 4.2:

    When you provide your own completion command (or list) you may want to disable the default matches. This can be done by setting disableDefaultCompletion to 1.

    I tried setting disableDefaultCompletion to 1 in the Preferences > Variables pane and quitting and reopening the app. I found that Bundle menu > Select Bundle Item and clicking Settings shows a list of all the settings, including my disableDefaultCompletion = 1 at the bottom. Apparently this doesn't do anything? (Other settings overridden by different bundles show as crossed out, which my settings is not.)

    I also searched the http://github.com/textmate/textmate repo for the string disableDefaultCompletion and it shows in the search results, so this is feature should exist there somewhere.

    I tried quitting the app and then on the commandline:

    defaults write com.macromates.TextMate disableDefaultCompletion true

    Relaunching and trying again (hitting Esc to the right of a close } in JavaScript mode) and it is still not disabling completion.