5 things we didn’t know Sublime Text 2 could do

Sublime Text is packaged with features, though some are some-more good famous than others. Alastair Lockie takes us off a beaten lane to find some dark gems in this absolute editor

Sublime Text 2 is distant some-more than usually a content editor; it combines overwhelming opening with a outrageous underline set. There are oodles of articles and blog posts out there to assistance we get started with this editor, and to learn we some of a obvious facilities such as a authority palette and a record switcher. This essay will take a somewhat opposite tack, and uncover we some of a lesser-known nuggets to assistance we fist a many out of this almighty editor.

1. Path paradise

5 things we didn't know Sublime Text 2 could do
The SidebarEnhancements plugin adds good trail duplicating features

File paths might not be a sexiest thing in a world, though it certain is a pain typing them out – generally when we have to embody them in to your HTML as tags all a time. Luckily, Sublime Text 2 is there to take a pain out of paths for you.

For this tip, you’ll need to implement a SidebarEnhancements plugin. The easiest approach to do that is with Will Bond’s Package Control:

  1. Follow a instructions
  2. Once installed, glow adult a Command Palette (cmd/ctrl + change + P) and enter Install into a automobile complete
  3. Type SidebarEnhancements into a subsequent automobile finish that pops adult and strike enter to bucket in a plugin

Got it? Good. Now let’s emanate a new JavaScript record and save it somewhere in your project. Fire adult a Command Palette (cmd/ctrl + change + P) and form in file copy. Behold, a raft of duplicate options for your pasting pleasure! The many common and stretchable choice that you’ll use is substantially a File: Copy Path From Project. This will give we a trail relations to your plan that we can use in your RequireJS or AMD procedure includes.

If you’re manually adding your resources into your HTML, afterwards we could use a Path from Project to stock a src attribute of your book tag, though we can go one step further. If we are observation a JavaScript file, afterwards we can name File: Copy as Tag script. You afterwards have a processed book add-on with a scold src charge prepared to pulp directly into your HTML. The same goes for CSS files, use File: Copy as Tag style to get a wholly shaped stylesheet link tag.

Pro tip: As a name suggests, a SidebarEnhancements opens adult a resources of options for files in a sidebar. Right-click a record and have a poke around.

2. Restraining multiselect

Restraining multiselect
The ‘Case Sensitive’ choice in a Find toolbar boundary multiselect

One of a excellent facilities of Sublime Text 2 is multi-selection; we can have mixed cursors permitting we copy, paste, revise and delete. The many common form of multi-selection is Quick Add Next (cmd/ctrl + D), that automatically adds a subsequent occurrence of whatever we have selected.

This is great. However, if you’re perplexing to rename a variable, infrequently we finish adult adding in selections containing a right difference with a wrong case. Let’s demeanour during an example:

Imagine we wanted to rename a stringHelper non-static in a above code. We name a initial stringHelper after a var, though afterwards when we Quick Add Next by a code, we finish adult with a StringHelper category and StringHelper from someOtherStringHelper comparison as well. We could skip over these with Quick Skip Next (cmd/ctrl + K), though if your refactor is utterly vast this can be a bit tedious.

Instead, let’s make certain we usually name a non-static itself by enabling box sensitivity. Bring adult a Find underline with cmd/ctrl + F, afterwards spin on box attraction by dire cmd + alt + C on Mac OS X, or (alt + C on Linux/Windows). Press escape to get out of Find. Then, when we try a multiselection again, we usually name a variable.

Pro tip: we can also capacitate Whole Word only preference regulating a same process though with a by-pass cmd + alt + W (alt + W on Linux/Windows). This would bar someOtherStringHelper only in a above example.

3. Supercharge your growth with Snippets

Supercharge your growth with Snippets
Snippets have an adjacent outline in a editor autocomplete

Some of a best programmers mostly report themselves as lazy. Why? Because they are always looking for ways to equivocate doing some-more work than they have to. A good approach to speed adult your outlay is to strap a energy of snippets.

Sublime Text 2 comes with a garland of snippets out a box, that we can activate by simply typing a initial few letters of a preferred formula until a automobile finish displays a dash option, afterwards attack enter. For example, form fun in a JavaScript record and a Function dash will be displayed in a automobile complete. Hitting enter will insert a new duty during that plcae with a duty name selected. Enter a name of your function, afterwards strike tab and a arguments will be selected. Type a arguments and strike tab again, and you’ll be inside a duty physique prepared to go. It’s tough to suppose a faster approach of formulating a function.

The built-in snippets are great, though to unequivocally get a many out of this underline we can write your own. To do this, name New Snippet… from a Tools menu to get a dash template. Put your dash within a CDATA section, regulating ${n:default} to conclude a add-on points, where n is a series of a add-on indicate and default is a default value for that add-on point. You can afterwards set a tabTrigger and range fields next to establish when your dash will glow (use cmd/ctrl + / to uncomment a fields).

Once you’re finished with your snippet, save it in your User package with a prolongation .sublime-snippet.

4. Slice and bones outlay files

Slice and bones outlay files
Use a energy of snippets to trim your typing

We’ve all been there. It’s late, you’ve got an obligatory emanate we need to fix, and your usually source of information is a large fat server dump. Let’s contend we need to get a ids of all a clients from a London bureau from this record below:

You could laboriously go by a record line by line, duplicating and pasting any id from London. But, if a record is hundreds of lines long, afterwards that’s not a fun approach to spend your Friday evening. Instead, let’s precedence Sublime Text to do a tough work for us. Stick a cursor in a word London in a outlay file, afterwards strike cmd + ctrl + G (or alt + F3 on Windows/Linux) to name all a London‘s. Hit the left arrow to pierce a cursor to a start of a word, afterwards use alt + left to name a adjacent id. Bingo! You can now duplicate your selection, open adult a new record and pulp them in.

Use a Sort/Unique Lines commands in a Command Palette to neat adult a outlay and forestall duplicates. From here, we can supplement a comma after a ids and use a Join Lines authority to ready them for an SQL statement, or format them however we like.

Pro tip: If we wanted to find ids from clients in both London AND Lisbon, we could use a regex hunt (cmd + alt + R for Mac OS X or alt + R on Linux/Windows) from within a Find underline to hunt for L….n instead.

5. Projects and Hot Exit

Projects and Hot Exit
Use projects to organize your workspace and customise settings

Many integrated growth environments (IDEs) support a idea of a ‘Project’, though Sublime Text 2 projects are mercifully simple. While operative in a folder, we can select Save as… from a Project menu to insist your stream setup. Once that is done, we can supplement and mislay folders from a plan regulating a Project menu, or for unequivocally fine-grained control we can open a .sublime-project record itself.

Sublime-project files are simply JSON pattern files that by default usually uncover we that folders we have in your project. For any folder, we can also mention a folder_exclude_patterns key, with an array containing all a folder patterns we wish to exclude, for instance [build, log].

As good as folders, we can also mention settings, that will overrule your User settings. This is a good small underline if you’re collaborating on a plan with a opposite add-on distance to your normal setting.

If we are a freelancer operative on mixed projects, afterwards switching between them is super elementary with Sublime Text 2. Just strike cmd + ctrl + P (ctrl + alt + P on Linux/Windows) to move adult a plan switcher and crack between your active projects. Here’s a kicker: if you’re in a center of a garland of changes and have proxy tabs open though wish to check something in another project, we don’t have to save everything. Sublime Text 2 lets we switch between projects, or even tighten a focus entirely, and, when we go behind to your project, it’ll be accurately as we left it.

I wish that even if you’re a seasoned Sublime Text 2 veteran, you’ve schooled something from this article. Sublime Text 2 is a hugely absolute editor, though it has a distant gentler training bend than hardcore content editors like Vim and Emacs. As such, it’s easy to feel like we ‘know enough’, though a small bit of digging around in a menus, Command Palette and preferences mostly yields luscious tidbits to assistance supercharge your development. Keep exploring!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Comment

Comments are moderated. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!


− 6 = two