Skip to content

Instantly share code, notes, and snippets.

@urbanij
Last active April 4, 2019 13:05
Show Gist options
  • Save urbanij/b43e5e0b4786ee78cd8e062c81e1e0f1 to your computer and use it in GitHub Desktop.
Save urbanij/b43e5e0b4786ee78cd8e062c81e1e0f1 to your computer and use it in GitHub Desktop.
Editing Sublime Text snippet

Editing/adding snippet in Sublime Text

Editing snippet

  1. Move to the folder where the installed packages reside, i.e. /Applications/Sublime Text.app/Contents/MacOS/Packages. You can hop there either by typing: cd /Applications/Sublime Text.app/Contents/MacOS/Packages or from the Application folder: right click on Sublime Text -> Show Package Contents -> Contents -> MacOS -> Packages

  2. Identify the target file. E.g. i want to change the default behavior of the for loop snippet of C/C++ because i find ++i in place of i++ hella annoying. With that in mind you can move on to

  3. select the responsible package C++.sublime-package and duplicate it

  4. rename the just duplicated file by adding .zip. The file will now appear as a proper zipped file.

  5. unzip it

  6. move to the folder Snippets inside the just unzipped folder

  7. identify the file of interest, in the above mentioned case it's named 030-for-int-loop-(fori).sublime-snippet

  8. edit the file according to your taste and save it.

  9. go back to the "root" folder where all the packages reside, see (1)

  10. (optional) move or clone the original file C++.sublime-package somewhere secure, just for a quick sort-of backup

  11. delete the .zip file previously created

  12. delete the file C++.sublime-package

  13. compress the folder that we just edited (in my case called C++.sublime-package 2)

  14. rename it to C++.sublime-package

  15. delete the unzipped folder (in my case called C++.sublime-package 2)

  16. leave a star to this GitHub Gist


Adding snippet

If you just need to add a new snippet you can simply use the tool that Sublime provides. From the menu bar: Tools -> Developer -> New Snippet...

Save it with extension .sublime-snippet in the suggested folder (should be under Packages -> User) and you're good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment