loading...

My Sublime Text Setup for PHP

restoreddev profile image Andrew Davis ・3 min read

I have been using Sublime Text for coding in PHP for several months now and over that time have accumulated several useful plugins and editor settings. I have not seen many recent articles about setting up Sublime Text, especially for PHP, so I want to share how my setup works and what has been most helpful for me to write code productively.

Preferences

Sublime Text has a preferences area where you can tweak the layout of the editor using JSON. Here are my favorite settings:

{
    "font_face": "Fira Code Retina",
    "font_size": 14,
    "line_padding_bottom": 2,
    "line_padding_top": 2,
    "highlight_line": 14
    "bold_folder_labels": true,
    "rulers": [80, 120],
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space": true,
    "ensure_newline_at_eof_on_save": true
}

I follow the PSR-2 style guide provided by the PHP-FIG so several of these settings have been very helpful in maintaining that style. The rulers setting shows a vertical line in your editor as a guide for the line length. PSR-2 sets a preferred limit at 80 characters and a soft limit at 120, so I show a vertical line at both lengths to know when I pass the limit. The tab settings ensure I’m always using a four space tab for indentation (yes, I prefer spaces to tabs). Often I forget to add an empty line at the end of the file, so the ensure_newline_at_eof_on_save setting will do it for you automatically. If you are curious, the blank last line is to make git diffs not appear for adding a return character to the above line when you start adding more code to the file.

One of my favorite convenience settings is the highlight_line preference. It will cause Sublime to highlight the line the cursor is on, making it really easy to find where you are typing. Finally, I use Fira Code as my font. It’s a really nice font that has ligatures. Sublime Text supports font ligatures now which makes your code look really clean.

Plugins

There are so many plugins for Sublime Text, it can be difficult finding the good and helpful ones. In no particular order, here is a list of all the ones I find most useful.

Sublime PHP Companion adds several helpful commands for PHP development. In particular, I really like the Find Use command which will automatically add a use statement at the top of your file for the class name under your cursor. DocBlockr will auto-generate doc blocks for your PHP methods, making documentation much easier. Vintageous adds vim keybindings (one of my favorite plugins). GitGutter will show you added and modified lines in the sidebar, making it easy to find new code you have written. The Babel plugin adds ES6 and JSX syntax highlighting. All Autocomplete will add auto-complete entries for all the files that you have open, making it easy to reference methods for classes you have open.

Theme

In the general release of Sublime Text 3, the team added a new theme called Adaptive which will automatically adjust the appearance of the sidebar and tab bar to match the chosen color scheme. My two favorite color schemes are Dracula and Solarized Dark (provided by default). In the past, I have used the Boxy Theme, but it has since been deprecated in favor of a newer theme.

My setup
Here is what my setup looks like now using the Dracula theme.

If you have some favorite Sublime Text plugins or settings, let me know in the comments. I’m always looking for more features to try out.

Here is a list of several blog posts that helped me create this setup:

Happy coding!

Discussion

pic
Editor guide
Collapse
perttisoomann profile image
Pert Soomann

Other than the age old tabs v spaces, which I can not get myself to change to stop using tabs, very good article :D

One very useful plugin I find helpful is "Function Name Display" - when in middle of class/function, it'll display the method name in status bar, so you don't have to scroll up on longer functions to see what part of the code you're modifying.

Collapse
dev_nope profile image
Vasile Stefirta πŸ‡²πŸ‡© ✈️ πŸ‡ΊπŸ‡Έ

Hey Andrew,

Great article! πŸ‘ I've been using sublime for a few years now and I really love it. Here are my user settings:

{
    "always_show_minimap_viewport": true,
    "bold_folder_labels": true,
    "color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
    "font_face": "Source Code Pro Light",
    "font_size": 15,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_guide_options":
    [
        "draw_normal",
        "draw_active"
    ],
    "line_padding_bottom": 5,
    "line_padding_top": 5,
    "overlay_scroll_bars": "enabled",
    "theme": "Material-Theme-Darker.sublime-theme",
    "translate_tabs_to_spaces": true,
    "tab_size": 4,
    "word_wrap": "false"
}

I really love the Material Theme in combination with the Source Code Pro Light font. Also, here are a few more packages I can recommend:

Collapse
restoreddev profile image
Andrew Davis Author

Definitely will check out the DotEnv extensions. Thanks for sharing your setup!

Collapse
prsion profile image
prsion

It is amazing text editor. If only he had a debugger like VScode and refactoring like PHPStorm than nothing else is needed at all. I have used PHPStorm (undoubtedly cool for a large team work), VScode -he is just good no more, and none of them does not bring such pleasure as SublimeText_3!!! It is Awesome!!!
Theme for SublimeText_3 - github.com/prsion/ThemesST3

Collapse
goplon profile image
Artur

Hi! Thnks for post! I think you just forget comma after "highlight_line": 14

Collapse
duyduong06 profile image
duyduong

i like default setting in subline text, and use a little plugin, i alway remote to server and code online with subline text.
pedicurespa.us

Collapse
mattdevio profile image
Matt G

Love sublime! Wish it was open source. I found better syntax highlighting with Naomi

Collapse
troyclose profile image
Troy Close

Hey Andrew thanks for sharing. PSR-2 has been deprecated in favor of PSR-12 since you wrote this.