Sublime Forum

Help with a keymap please


I want to have a keymap that opens a new_file then opens the prompt_save_ as from one key selection.

I know someone is bound to ask “why bother when it only saves one key selection”
The answer is this.

  1. it doesn’t just save one key selection, it saves 50% of the work of opening and saving.
  2. my snippets are scoped to specific sources ergo I need to save before using snippets.
  3. It gives me an opportunity to learn a bit more about ST2 and JSON.

This is what I have tried. The JSON validates - it just doesn’t work. Does anyone have an idea what I may be doing wrong?

   "keys": ["ctrl+alt+n"],"command": "insert_snippet", "args":
       {"keys": ["ctrl+n"], "command": "new_file"},
       {"keys": ["ctrl+shift+s"],"command": "prompt_save_as" }


I agree this is pretty handy. I do it using the AdvancedNewFile plugin.
Once installed pressing ctrl+alt+n will open a small prompt for you to enter the filename of the new file.



You don’t need to save a file to activate snippets. You can set a syntax of a view manually (by clicking on the right in the status bar, using the View → Syntax menu or searching for “Set Syntax:” in the command palette).

Unfortunately, what you want to do is not possible this way. args must be a mapping (or object, like you say in JavaScript) and the arguments must be accepted by the receiving command.

See also

Because you are creating a new view and want to run a command on that new view, you need to create a Python plugin for this.

Otherwise, this plugin could have helped you.



thank you both for your replies.

bnorgd: I added this but nothing is happening. perhaps i’m missing something.

FichteFoll: the reason I am using snippets this way (remembering I am fairly new to ST) is this:
I will be saving the file at sometime, so I may as well do it first.
the reason snippets are source specific is because I keep the names very similar ie. navh for html, navc for css etc. this means when I am in css and type na, navc will be the top selection. I don’t need to select from a list. If I was not source specific and typed na I would have a list from which to choose which would mean either going down the list or continue to type. both are extra keystrokes, which is what I am trying reduce. that’s just the way I think, I hope it makes sense.

I looked at the plugin you suggest and will try it later today.

thank you both.



both links were actually to the same plugin and it works perfectly. thank you for that.
I do have one question, my projects all have the same file structure with sub- directories for css, inc, img etc.
as I may be in either root or one of the subs (ie. \inc) and want to save a new file in \css what would be the syntax? as far as I see they all save to the current dir.




You can provide parameters to the advanced_new_file_new command, or use the advanced_new_file_new_at command. Parameters are explained in its wiki:



got it, thank you, much appreciated.