How can I make a command that creates a new file with template text?


Hi, I’m trying to make a command that will open a new text editor with template text. I’ve looked at similar questions and poked through the wiki, but I can’t seem to get it to work. I want to make it a command instead of just doing ctrl+n and using a snippet because I plan on binding it to a toolbar icon. Here’s my code.

atom.commands.add 'atom-text-editor',
'custom:new-template-file', ->
    editor = atom.workspace.buildTextEditor(); (editor) ->
    editor.insertText('[insert template text]')

Help would be much appreciated.


Your indentation is wrong. This works:

atom.commands.add 'atom-text-editor', 'custom:new-template-file', ->
  editor = atom.workspace.buildTextEditor() (editor) ->
    editor.insertText('[insert template text]')


Thanks, works perfectly!