Tools menu -> Developer -> New Plugin…
Replace the contents with:
import sublime
import sublime_plugin
import binascii
class ReplaceCharCodeCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection_contents = self.view.substr(self.view.sel()[0])
is_hex = None
try:
value = int(selection_contents, 16)
is_hex = True
except ValueError:
is_hex = False
replace_with = None
if is_hex:
replace_with = binascii.unhexlify(selection_contents)
else:
replace_with = binascii.hexlify(bytes(selection_contents, 'UTF-8'))
self.view.replace(edit, self.view.sel()[0], replace_with.decode('UTF-8'))
Save it in the folder ST defaults to, as a file named with a .py
extension.
In your User Keybindings (from the Preferences menu), add:
{ "keys": ["alt+x"], "command": "replace_char_code" },
and save it