Keymap Sublime Text 2 File Type?

北城以北 提交于 2019-12-22 11:24:47

问题


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 highlight Set 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!