Search code examples
autocompletesublimetext3keyboard-shortcutssublimetext

How to disable/override the enter key for autocomplete?


In Sublime Text 3, I want to disable the enter key to select an item from the autocomplete drop down, and only allow the tab key to do so.

I found this section in the inbuilt Default (OSX).sublime-keymap file:

{ "keys": ["enter"], "command": "commit_completion", "context":
    [
        { "key": "auto_complete_visible" },
        { "key": "setting.auto_complete_commit_on_tab", "operand": false }
    ]
},

It seems that if I remove this from the config that enter will not select an item in the drop down. Unfortunately it is not recommended to change this file, and only to override it in my User files. I don't think I actually can edit it without modifying the .app contents.

I tried to override it by removing different sections, and also remove everything except "keys": ["enter"], but nothing seems to work.

How would I go about achieving this without modifying the inbuilt Default (OSX).sublime-keymap and only the User/Default (OSX).sublime-keymap file?


Solution

  • I have never used Sublime Text 3, but I don't think the following has changed since Sublime Text 2.

    What you want to achieve is actually a standard feature in Sublime Text. You just have to turn it on.

    This line from your the code you quoted …

    { "key": "setting.auto_complete_commit_on_tab", "operand": false }
    

    … means "only execute the command if the setting called 'auto_complete_commit_on_tab' is set to false". So simply turn on that setting.

    In Default/Preferences.sublime-settings:

    // By default, auto complete will commit the current completion on enter.
    // This setting can be used to make it complete on tab instead.
    // Completing on tab is generally a superior option, as it removes
    // ambiguity between committing the completion and inserting a newline.
    "auto_complete_commit_on_tab": false,
    

    Put "auto_complete_commit_on_tab": true in User/Preferences.sublime-settings. Both mentioned files can be accessed via the Preferences menu.