Hi Feilin. You can use Karabiner to disable the Esc key globally, for an individual app, or for multiple apps and enable/disable from the menu bar or using keyboard shortcuts. Note that the Esc key is disabled, not just the text completion feature. Install the app at your discretion; backup your drive before installing.
You may want to set up multiple profiles to easily switch between them to enable/disable the Esc key.
In the example above there are profiles for Default, with no modifications, Disable Esc, which acts globally, and Disable Esc TextEdit Only, for TextEdit only. You can disable the Esc key globally from the Change Key pane in Karabiner's Preferences, accessed from the menu bar.
To disable the Esc key in TextEdit only, copy and paste the following XML code using TextEdit into private.xml located at ~/Library/Application Support/Karabiner/private.xml and save:
<?xml version="1.0"?>
<root>
<item>
<name>Disable Esc TextEdit Only</name>
<identifier>private.disable_esc_textedit_only</identifier>
<only>EDITOR</only>
<autogen>
__KeyToKey__ KeyCode::ESCAPE, KeyCode::VK_NONE
</autogen>
</item>
</root>
Reload the XML from the Change Key pane of Karabiner's Preferences. The private.xml item will show up in the Change Key pane.
To enable/disable using the profiles, access from the menu bar.
You can also enable keyboard shortcuts from the Change Key pane by typing "switch profile" in the search box and selecting.
If you wish to filter to specify more than one app to disable the Esc key, you can use comma separation in private.xml:
<only>EDITOR, SAFARI</only>
Karabiner has an XML of predefined app definitions, although you can add app definitions to private.xml for apps not predefined. There are also further refinements for filtering such as by ui element role, window name, etc. See Karabiner's Manualand private.xml Reference Manualfor further information.