Useful plugins for Sublime Text 3

Sublime Text 3 is powerful and really kicks ass even in its bare installation. But, when you power it up with proper combination of plugins it simply kills entire life on the planet!

Package Control claims to have over 1800 plugins for Sublime Text 3. Browsing this number of them seems impossible. Many of them are abandoned, some are for very specific reasons.

In this article I am only listing just a few plugins that I am using within Sublime Text 3.

If you’re reading this text, I assume, that:

  • you have Package Control installed and
  • you’re after reading my Beginning with Sublime Text 3 article.

If not, skip back and pass these two points.

Note, that installation of most plugins doesn’t require Sublime Text 3 to be restarted. They simply starts working at once. Isn’t that cool?

Functional plugins

Real PHP linter

What is a linter? It is your PHP code’s proofreader that works… as you type!

I’ve opened any PHP file and made any mistake. For example, I changed $file = 'foo'; to $file => 'foo';. And… bang! Line was highlighted with a border and I’ve got:

Error: unexpected ‘=>’ (T_DOUBLE_ARROW). Line 159, Column 51.

What to expect more? Beat that with Netbeans! :]

This is the whole separate story, that you’ll have to dig yourself, if you run into any troubles or if you’re willing to. Here, I limit myself only to show the simplest path to achieve acceptable results — real-time syntax checking in Sublime Text. And yes, it is a real ass kicker!

There are many linters for Sublime text. Searching Package Control repository for sublimelin many results. Two most popular are: sublimelint and SublimeLinter. Key differences:

  • sublimelint is less popular (TOP100), much less often updated and contains much less linters (in case you’d need something else than just PHP), but have then build-in and have very easy extending mechanism for adding new ones,
  • SublimeLinter is more popular (TOP25), much more often updated and have much more linters (many of them are in many variations, for example for PHP only there are four or five different linters), but all of them must be installed as separate package (plugin) and there aren’t to easy ways to extend it beyond.

It is also said, that SublimeLinter is working slowly or unstable on some machines, which is why users of these machines reverts back to sublimelint; I haven’t noticed anything like that (maybe because under Sublime Text 3 it works much more stable).

Installation was limited to pressing Ctrl+Shift+P, typing ins and installing two packages: SublimeLinter and SublimeLinter-php. After that, I had to restart Sublime Text 3. I also had to verify, that my PATH system variable contains valid path to php.exe file.

Note, that SublimeLinter isn’t just another plugin, but actually a large ecosystem. You can see many of its options, tools and possibilities in Tools > SublimeLinter menu. It is a really good piece of job and an effect of hundreds of hours of hard coding. If you find it useful (how wouldn’t you), then I strongly advice you to consider donating to its author.

GotoDocumentation

Ever dreamt about selecting foreach in your code, pressing F1 and being transfered within miliseconds to php.net site with open PHP on-line documentation for foreach loop? Now you you can stop dreaming and start doing this everyday. With the GotoDocumentation.

Installation, as above and as everything with Package Control:

  1. Hit Ctrl+Shift+P, type inst, type or paste GotoDocumentation and hit Enter.
  2. Open Preferences > Key Bindings — User
  3. Add following line: { "keys": ["f1"], "command": "goto_documentation" }.

You’re done. Select any piece of text and hit F1 to see magic happening.

CTags

CTags plugin is used to emulate “goto source definition” functionality. It is (at least for me) the key part of coding in professional IDE. However, its installation and configuration is quite time-consuming (because you need to take care about many things), so I separated it into another blog article.

You’ll find it here: CTags and Goto source definition functionality in Sublime Text 3.

Modific

This plugin brings a simple gutter icons to inform you, which lines were added, removed or modified in currently opened file versus commited version of currently edited file. It also provides you with a few useful keyboard shortcuts for quick management of very basic git commands.

Again, description of this plugin is beyond scope of this article, so I moved it into this article.

Note, that Modific works with git only. There are some plugins that brings the same functionality for other VCSes (i.e. VCS Gutter).

Editor-based plugins

DocBlockr

The DocBlockr plugin is everything about creating comments/documentation blocks. Install it using Package Control or the traditional way.

And that is all. Once, installed, it is there, ready for you to type /** and hit Enter in a line before any function, method, class or variable.

It works exactly as similar functionality in Netbeans worked, but (of course!) it gives you some additional sweepstakes. Variable types are better discovered and both variable types and variable description blocks are already aligned in the same column, so you don’t have to get yourself wako with tabbing around.

Code completion for PHP

Sublime Text 3 comes with basic code completion functionality, including PHP language. If you’re fine with it, then skip this chapter. If, however, you’d prefer code completion on steroids, install PHP Completions Kit plugin.

Code completion using this plugin starts immediately, when it is possible. If you want to force it, press Ctrl+Space. Select proper completion entry with arrows and hit Enter to select it (and enter to editor) or keep pressing Ctrl+Space to select each following one.

Keep in mind that it works only in proper context (i.e. .php file etc.), so testing it on empty document will fail and suggest that plugin is not working.

In basic usage (follow to plugin webpage for more advanced uses) it allows you to insert methods, functions, constructs etc. and — where possible — allows you to cycle through arguments using Tab button. Just like in Netbeans, phpStorm and many more IDEs.

Unlike Netbeans, it is much smarter. It recognizes which arguments are required and which are optional.

Remember to remove default Sublime Text’s PHP completions, as they interfere with these provided by PHP Completions Kit. To do this, you should:

  • Select Preferences > Browse Packages,
  • create a folder named PHP in opened explorer window
  • create empty PHP.sublime-completions file inside this folder.

Restart Sublime Text 3 to complete removal process.

BracketHighlighter

Small plugin that extends base Sublime Text 3’s bracket highlighting functionality.

Base ST3 only underlines four types of brackets ((), [], <> and {}). BracketHighlighter highlights them plus adds special annotation to gutter and supports many more type of “brackets”, including:

  • Single and double quotes
  • HTML tags
  • PHP conditionals
  • Markdown bolds and italics
  • And many more

It also offers a cool feature, of highlighting nearest brackets block, when you place cursor anywhere within this block. While base, build-in implementation only highlights brackets, when your cursor is in the line of either opening or closing brackets.

If you have “Modific” and “BracketHighlighter” installed together, gutter icons generated by “Modific” (git status icons) will override (hide) “BracketHighlighter”‘s ones.

JSON prettyfier

There are many Sublime Text 3 plugins written to prettify JSON code that is to convert “compressed” one to indented code. I decided to use Pretty JSON plugin.

Mainly, because:

  • it works both way: can prettify and compress JSON strings,
  • can work on boths selection and entire file / buffer (can be disabled in settings),
  • comes with handy keyboard shortcuts: Ctrl+Alt+J (jsonize?) to prettify and Ctrl+Alt+M to compress (minify),
  • has additional tool for converting JSON to XML (there’s no shortcut, press Ctrl+Shift+P to open Command Palette and search for Pretty JSON: JSON 2 XML).

And there’s only one, small glitch. It does not rely on tab_size user setting, but instead encorces own configuration. By default, it uses two spaces.

You have to:

  • open Preferences > Package Settings > Pretty JSON > Settings — User
  • and put {"indent":4} file (minified with “Pretty JSON” itself, of course! :])

to change indent used by this plugin to four spaces.

Follow to plugin’s GitHub repo to read, how to change this to tabs.

LineEndings

The Line​Endings is small, but works like a charm (as other similar, are reported to not work at all). Visit it’s GitHub repository to get a few details, because on its Package Control page there is no description.

It not only works, but also gives you an additional functionality — you can change not only line endings, but also indentation method of all open files in one step.

After installation:

  1. Open all files, in which you want to convert / change line endings and/or indentation method.
  2. Press Ctrl+Shift+P to open Command Palette and start typing lin to locate Line Ending to all views: Windows (for example).
  3. Select it, hit Enter, and… you’re done!
  4. Repeat step 2, but:
    1. Type spaces to locate Indentation: Convert to all views to Spaces or
    2. Type tabs to locate Indentation: Convert to all views to Tabs
  5. This will change indentation method of all open files.

This plugin is very useful when you’re working with Git. Especially when is set to (for example) keep local files with Windows line endings, but commit them with Unix ones (or any other combination). I found it most welcome when I had to convert this way all the forty Javascript locale files of some library.

Doing this manually on Notepad++ sounded terrific.

Final words

Once again, these are just few of nearly two thousand plugins available. If you want to go further, simply jump up to Package Control website and start digging for some pearls, that I might pass by.

Leave a Reply