问题
I am working on setting up my own keymaps and was wondering if there is the option to set keys to switch the file type that is being worked on. So for example, if I have a regular plain text file and want it to be a css file, I would have a keymap that would change the document type to css. Possible? If so, please explain to me how you have done this.
Rob
回答1:
While the individual shortcut solution is great, it requires editing the config files and most importantly remembering all the shortcuts you create for each sytax.
In the case of switching file formats it might be more useful to quickly access the required format via the command palette:
- Press CTRL+SHIFT+P to bring up the
Command Palette
- Type
CSS
to highlightSet Syntax: CSS
command - Press ENTER
This is great because it provides quick access to all the formats available. Start typing set syntax...
and all the available formats will be shown.
回答2:
The keybinding for this would be:
{
"keys": ["YOUR_SEQUENCE"],
"command": "set_file_type",
"args": {"syntax": "Packages/CSS/CSS.tmLanguage"}
}
How to discover command names:
- Open the console
- Type
sublime.log_commands(True)
- Go to an open tab
- Open the command palette and type
Set Syntax: CSS
The name of the command and it's required arguments should be logged to the console. From there you just put it in the right JSON syntax.
来源:https://stackoverflow.com/questions/11814516/keymap-sublime-text-2-file-type