I am back to using Sublime Text 2 after some time and I noticed that I had made shortcuts to type certain expressions faster. For example, in Java, the common System.out.println()
is immediately suggested as the first choice after typing pr
in the editor since pr
was the trigger that I chose for System.out.println()
. After typing pr
, I press enter and System.out.println()
is written on the editor.
I don't remember how I did this or what is the name of the procedure to do this (hence, it is hard to search it online). All I remember was editing some text file in Sublime and adding the shortcut.
Creating snippets or "shortcuts" is easy in Sublime Text.
For your example, you would simply have to do the following:
Go to Tools > New Snippet...
Inside the
CDATA
brackets, put the code snippet you want to be generatedUncomment the
tabTrigger
tag and put "pr" inside it. This is the shortcut you want to use to generate the snippet.Uncomment the
scope
tag and putsource.java
inside it. This will make the this snippet only show up when you're working with Java files.Save the file to your Packages > User folder and name the file whatever you want. Make sure you end it with a
sublime-snippet
extension.In this example, I saved it as
println.sublime-snippet
. This is what it ended up looking like in the end:You can learn more about customizing your snippets with things like tab stops here.