Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 956
gak Avatar asked Mar 14 '13 23:03

gak


2 Answers

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.

like image 66
lydell Avatar answered Sep 23 '22 17:09

lydell


You can assign it to a non existent command. Try adding the following to User/Default (OSX).sublime-keymap

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

Granted if you install/write a plugin that has a command noop you will need to change this command.

Edit

Lydell's solution is better :) Forgot about that setting (though it is in the context so I should have known...). Guess my answer is a more generic "how to disable a keybinding".

like image 28
skuroda Avatar answered Sep 20 '22 17:09

skuroda