Skip to content

Instantly share code, notes, and snippets.

@ptim
Created March 12, 2014 11:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ptim/9505499 to your computer and use it in GitHub Desktop.
Save ptim/9505499 to your computer and use it in GitHub Desktop.
ST3 super simple plugin: Save the current file with encoding UTF8, then close.
import sublime, sublime_plugin
'''
A response to: http://stackoverflow.com/questions/19831757/how-to-create-macro-in-sublime-text-3-with-saveas-and-close-file-command
Save the current file with encoding UTF8, then close.
To trigger the command with 'Command Option Shift 8',
add the following to your Sublime Text > Preferences > Keybindings - User
[
{ "keys": ["super+option+shift+8"], "command": "save_as_utf8"}
]
'''
class SaveAsUtf8Command(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("save", {"encoding": "utf-8" })
self.window.run_command("close")
@ptim
Copy link
Author

ptim commented Mar 12, 2014

It doesn't work as a macro; maybe these commands are out of scope for a macro (eg a window command not a view command?).

[
    { "command": "save", "args": {"encoding": "utf-8" } },
    { "command": "close", "args": null }
]

Looks like it might work, but produces:

Unknown macro command save
Unknown macro command close

in the console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment