Chapter 3. Snippets, Macros, and Key Bindings

This chapter will help you to master snippet and macro skills and guide you through customizing and managing your key bindings. In this chapter we will cover the following topics:

  • Getting to know a snippet
  • Understanding your first snippet
  • Using Package Control snippets
  • Recording, editing, and using macros
  • New key bindings

Getting to know a snippet

As developers, we all get to write the same short code fragments over and over again on different files and projects. The best example of this is the following code:

<!DOCTYPE html>
<html>
  <head>
    <title> My cool Website </title>
  </head>
  <body>
    <p> Hello World! </p>
  </body>
</html>

We all have written something similar so many times. That's why Sublime has the snippets feature. Snippets are smart templates that insert the right text when we need it, where we need it.

Let's see this example live by using Lorem ipsum. We have this empty HTML page that we wrote using our awesome, fast fingers. Now we want to enter some placeholder text inside the <p> tags, as shown in the following screenshot:

Getting to know a snippet

We just type the trigger letter for our snippet, in this case l, and we get all the options. Pressing Tab will insert the snippet as shown in the following screenshot:

Getting to know a snippet

Yes! We now have a Lorem ipsum. We could also achieve this by writing lore and pressing Ctrl + space on Windows, Linux, and OS X. Because we do not have other snippets starting with lore, Sublime will know exactly what we meant.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset