This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Use Sublime Text Snippets to Avoid Repetitive Typing

    Yoni WeisbrodYoni Weisbrod

    Speed up your Sublime Text workflow by creating snippets out of boilerplate code. Sublime Text snippets are smart, configurable, and prevent repetitive typing.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    When I type two brackets and press tab, this snippet that I've already defined creates a fat arrow function and allows me to quickly supply the function argument and then the body. I've also defined a snippet to generative React native components that I can quickly name and populate.

    To create a new snippet, create an XML skeleton with the snippet tag. You can also use the built-in skeleton by going to tools, developer, new snippet. Then this shows you some of the properties that you can define. To find the directory to save it in, browser packages, click user, and use the Sublime snippet extension.

    Our snippet is triggered by typing two brackets and then pressing tab, so that'll be our tab trigger. Next, we'll add our content denoted by the seed data syntax. Our snippet now works, but it doesn't allow us to pre-fill the argument or the body.

    Let's add that functionality by putting in a placeholder, a dollar sign and a number. First, the user will fill out the function argument, and then we'll add another placeholder for the function body. Now, let's make it even easier for the user by adding a default argument X and a default body so that the function isn't empty.

    When we test it out, we can see that we can automatically pre-fill the first argument and then cycle right to the body using the tab key.

    The last thing for us to do is to prevent our snippet from running on non-JavaScript files by scoping it to source JS. You can find the scope in any file by running ctrl+shift+P on Mac or ctrl+shift+alt+P on Windows.

    Discuss

    Discuss