1
votes

There are a lot of Sublime text snippet packages that exist - one issue I see is if I want to use these predefined snippets in file types other than the scope they are defined in, it would mean editing every single snippet and changing the scope parameter to include xyz file type.

For example, every snippet in this jQuery package is only limited to .js file scopes to use the snippets, but I mostly only need to use these snippets in .cfm document types.

https://github.com/SublimeText/jQuery

Is there some way to automatically change the scopes of snippets for packages like this instead of opening up every single snippet and modifying its scope?

Thanks!

1

1 Answers

0
votes

Assuming Sublime Text 3 (OSX) for this answer

I doubt there is a preference feature that can help here, so I think the best solution is to customize the package via a short script that replaces the scope parameter with new one in each of your files. In your package directory of snippet files:

sed --in-place=.tmp 's:<scope>source.js</scope>:<scope>source.js,source.cfm</scope>:g' *

Notes:

  • this replaces every occurrence of <scope>source.js</scope> in files in your directory.
  • this appends the new scope. if you don't want it to work in js files remove the source.js, after the second :
  • using GNU sed, for OSX sed you may need different flags
  • original file is stored to *.tmp, you can remove it once you are done.
  • I'm using an alternate regex delimiter : to avoid colliding with xml tag.
  • The scope i'm calling source.cfm might have a different label, check from a cfm file in your console, run this command to view the current scope label:

    view.run_command("show_scope_name")
    

Referencing How can I replace a string in files