2

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

pertrai1
  • 4,146
  • 11
  • 46
  • 71
  • 2
    CTRL+SHIFT+P, type "CSS", ENTER should do it too. – Strelok Aug 06 '12 at 05:05
  • This is the best solution for me as it is easier to use for various files. The below looks interesting but would take me some time to really grasp. I don't see how I can mark this as the answer? – pertrai1 Aug 06 '12 at 12:29
  • I will move it as an answer so other people can see it and you can mark it as accepted answer. – Strelok Aug 06 '12 at 12:32

2 Answers2

6

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.

iconoclast
  • 21,213
  • 15
  • 102
  • 138
Liam Cain
  • 13,283
  • 5
  • 39
  • 29
  • Hi @BoudinCode, thanks for your tip , but how can i bound a command like 'command+shift+p, type snippets' do , i know , just list the snippets ? Thanks very much ! – dfang May 28 '13 at 02:00
  • @BoundinCod If you type command+shift+p you can then type snippet and see a list – jasonleonhard Dec 31 '14 at 03:59
5

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.

Strelok
  • 50,229
  • 9
  • 102
  • 115