Sublime text расширения php

My Sublime Text Setup for PHP

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

  • All Autocomplete
  • Babel
  • BracketHighlighter
  • DocBlockr
  • Git
  • GitGutter
  • PHP Companion
  • PHP Getters and Setters
  • Vintageous
  • A File Icon
  • Sublime Linter
  • Sublime Linter PHP

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.

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:

Источник

Essential Sublime Text 3 Plugins for PHP Developers

Sublime Text has got to be one of the most popular text editors out there for coding. Although still in beta, Sublime Text 3 is a relatively stable and very usable. I’ve personally been using it for over 2 years now both at work and at home. It’s sophisticated, lightweight and easy to use. It also works on all the major platforms: Windows, OSX and Linux.

Sublime Text is not quite an IDE (Inte­grated Devel­op­ment Envi­ron­ment), but with the installation of a handful of packages/plugins you can really make it the ideal editor for developing PHP in.

There are some great packages out there for Sublime Text to help PHP developers improve quality of code and workflow. These are what I consider the essential packages for developing PHP in Sublime Text 3.

Package Control

First up is Package Control. Why this doesn’t come pre-installed I do not know. I suspect the majority of Sublime Text users will already have this installed, but if not get it now; it will make the installation of all the other packages listed here (and many more) extremely simple. It’s like the equivalent of apt-get or homebrew if you’re familiar with them. Rather than having to download manually or git clone packages to your Packages folder you can simply install (and remove) packages via the Command Palette.

Once you start using Package Control you will wonder how you survived without it!

SublimeLinter / SublimeLinter-php

Every developer makes the occasional typo; forgetting to close some brackets, missing off a semi-colon, etc.. To help avoid these mistakes we can use a linter. SublimeLinter provides a framework for linting. The linters themselves are distributed separately as additional packages; for PHP you will want SublimeLinter-php which provides an interface to php -l for checking syntax.

Other useful linters for developers include SublimeLinter-jshint for JavaScript, SublimeLinter-json for JSON and SublimeLinter-csslint for CSS .

phpcs

Well written code should use a consistent coding standard, i.e. type of indentation, naming conventions, use of whitespace, bracket placement, etc.. Whatever standard you are working to, phpcs will help you to conform to them.

Unlike the other packages this one requires a handful of external libraries and some configuration to get it working; you will need PHP CodeSniffer, PHP CodeSniffer Fixer, and PHP Mess Detector. Install these libraries and set their execution paths in the phpcs settings in Sublime and you should be good to go.

When you attempt to save a file it will sniff out any issues with the file’s styling. PHP Mess Detector will check for things like potential bugs, over-complicated expressions and redundant code.

You can define the coding standard you want to develop against in the package’s setting. Popular standards like PSR -2 and Zend are available, plus many custom ones like CakePHP that can be installed and configured.

EditorConfig

EditorConfig provides a way of maintaining some coding style consistency between different editors and IDE s. This is particularly valuable when collaborating with others, some of whom may not be using Sublime Text to code with. Styles for a project are defined in a .editorconfig file which can then be read by the text editor/IDE and enforce them. This is useful for defining tab styles and line endings among other things. Most editors have plugins available to support EditorConfig including Atom, Coda, PhpStorm and, of course, Sublime Text.

You can find out more about EditorConfig and what you can define in the .editorconfig file over on the official website. Details of the Sublime Text EditorConfig package can be found on GitHub.

DocBlockr

Good code should be well documented. PHPD oc is a pretty much universally accepted means of doing this in PHP ; although many developers find documenting their code tedious. DocBlockr simplifies the process of adding PHPD oc (and JSD oc) comments by autocompleting /** by pressing Enter or tab taking away some of the pain.

Func­tion Name Dis­play

This is a really simple little package that displays the current function that the cursor is placed in the status bar at the bottom (next to the line number).

VCS Gutter

If you’re working with Git, Mercurial, or SVN then VCS Gutter is a handy package for adding visual clues as to what has changed in a file since the last commit. It will show a small icon in the gutter to indicate what has been added, modified or deleted.

One slight issue I’ve found with this package is that if you want to view a large log file in Sublime it can slow the responsiveness of the editor considerably. In these cases I tend to temporarily disable VCS Gutter using Package Control.

Final Words

Those are my seven essential packages for developing PHP in Sublime Text 3. What do you use? Feel free to contribute your suggestions in the comments below.

Источник

Читайте также:  What can you do with java yahoo
Оцените статью