Is sublime text good 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 the 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.

  • 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 that you are writing.

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:

  • Sublime Text [3] for PHP Developers | MattStauffer.com
  • //wesbos.com/sublime-text-5-visual-tweaks/
  • How to configure Sublime Text for PSR Standards | Development Simplified

Happy coding!

Sublime Text 3 has awesome packages for all kinds all things and in this blog post I will write about packages that make me happy when using for web development. So let's start!

Package Control

First things first, We need to install Package Control to install other packages. To install package control we open Command Palette, to open it go to Tools->Command Palette or with shortcut Shift+Ctrl+P on Linux.

Here is the picture:

now we can install other packages with Package Control. You can search and install other packages by name via opening command palette and typing Install Package then you just type the packages name you want to install. Also we can browse packages on //packagecontrol.io  and you can read documentation, usage and configuration of packages.

PHPFMT

The first package I install after Package Control is phpfmt. This packages is a must have for php developers. With PHPFMT you can format your code when you save file, to install packages using package control press Shift+Ctrl+P to open command pallette and type 'install' then type the package name you can to install in our case this is phpfmt.

Before we can use this package we must define path to php binary file. Open config settings Preferences->Package Settings->phpfmt->Settings - User. Attention! never modify Settin_gs - Default file as the changes will be lost once Sublime updated.

   Specify php_bin to location of php binary and don't forget to set       

   format_on_save to true and then you can forget about all this as it

   will format your php code automatically.

SublimeLinter

SublimeLinter PHP [and its required dependency, SublimeLinter] rely on PHP's built-in linter. This is a simpler version that only runs the linter, nothing else. This check errors on your php code. Install it just like you installed phpfmt.

GitGutter

GitGutter shows you git diff on Sublime. modified or deleted, updated?

SideBarEnhancements

SideBarEnhancements as the name suggests extends sublime's sidebar.

SFTP

Great package enabling very comfortable use of SFTP, FTP and FTPS. It supports remote folders browsing, editing and synchronization between local and remote files. Also regular upload, download, save or file open.

jsPrettier

This package is not for php but it is my go to package when working with javascript files. This package like phpfmt formats javascript code. Before using this package we must install prettier depency install with this command

npm install -g prettier

Then install jsPrettier package and open settings file like we opened on phpfmt. As an example config:

{
	"debug": false,
	"prettier_cli_path": "/home/tasqyn/.asdf/installs/nodejs/9.2.0/.npm/bin/prettier",
	"node_path": "/home/tasqyn/.asdf/shims/node",
	"auto_format_on_save": true,
	"auto_format_on_save_excludes": ["*/node_modules/*"],
	"allow_inline_formatting": true,
	"custom_file_extensions": [],
	"max_file_size_limit": -1,
	"additional_cli_args": {},
	"prettier_options": {
		"printWidth": 100,
		"singleQuote": false,
		"trailingComma": "none",
		"bracketSpacing": true,
		"jsxBracketSameLine": false,
		"parser": "babylon",
		"semi": true,
		"requirePragma": false,
		"proseWrap": true
	}
}

prettier_cli_path - path to prettier.

node_path - path to node

You can change settings accordingly to your needs.

Conclusion

These are the packages I use all the time. Of course there are many packages for Sublime Text 3, You can browse them on packagecontrol.io and choose your favorites.

This is my first blog post like ever so there be many mistakes feel free to point it out.

Thank you for reading!

Can you use sublime for PHP?

Sublime Text 3 is an exceptional choice for PHP developers, even though it requires installing additional libraries and files. Once you are done with it, you can quickly learn how to run php file in sublime text. You may need to install more plugins to work correctly.

What IDE should I use for PHP?

NetBeans, the most widely used PHP IDE for PHP application development. This tool comes with all the rich features, which supports multiple languages. NetBeans was initially used for Java development, but the current version of this tool is lightweight, faster as well as supportive for PHP development services.

What is sublime text good for?

Sublime Text is one of the most popular text editors in the world. It's jam-packed with powerful features like multi-line editing, build systems for dozens of programming languages, regex find and replace, a Python API for developing plugins, and more.

Is Sublime Text good for web development?

Sublime Text is one of the most popular code editors available right now. It is adored by many programmers for it's speed, simplicity, and rich plugin ecosystem.

Bài mới nhất

Chủ Đề