scimoz.paste() operates directly on the scimoz buffer the moment it is called. It is not aware of the snippet template that it is called from, so the output makes no sense.
EDIT: Another way of looking at snippets: the body of the snippet is evaluated apart from the insertion. The paste() call would have worked if the evaluation and insertion were handled line-by-line. But in fact the paste() call happened during evaluation and before insertion – it just cut and pasted the text in the same place (evaluation phase), then inserted the triple quotes (insertion phase).
@ervumlens is correct about when the code is running and that’s why it’s showing up in the wrong place.
Two things, scimoz.selText will grab all selected text on the page (multi cursor stuff). Just something to be aware of. You can use scimoz.multipleSelection to see if there is multiselection.
Also, please use the new API, var scimoz = require("ko/editor").scimoz();
The scimoz() and scintilla() functions are helper methods, and while they are unlikely to change they should not be relied on.
By the way you do not need to use any EJS for this snippet at all, Snippets have the “Selection” mechanic built-in. Just press the little arrow next to the input field.
Search the Komodo help getSelection and it finds nothing and the Macro Api help is completely out of date so I had no way of knowing about editor.getSelection. Also [[%s]] does not quite do because if there is no selection it throws an error. I wanted a macro that used the selection if it was there but otherwise not. How do I find out what the editor methods are? The docs really need bringing up to date!