Most of the content here "maybe" applies only to Sublime Text 3, please note that Sublime Text 2 was last updated on 8 of July 2013
For PHP as for other languages the plugin that works a lot is Codeintel, it uses the autocomplete while typing, so it doesn’t need commands. It recognizes custom functions, classes and namespaces (created in your project), even if it’s in a different file.
Install the Sublimecodeintel Preferences > Package Control > Install Package
Typo SublimeCodeIntel
, and select it to install
Install Phpintel Preferences > Package Control > Install Package
Typo PhpIntel
, and select it to install
Now you should select the folder of your project and drag it to Sublimetext, like this:
Now browse through the sublime itself in the project files, open any file and press Ctrl+S, Codeintel will take a while the first time, but will generate in your project folder another folder called .phpintel
, it contains a mapping and caches of your classes, every time you use Ctrl+S he’ll update this, then just test:
Note that the namespace and class are not native, although it recognizes PHP natives as well.
Other tips
Other interesting settings that you can take into consideration is to edit Settings, go to Preferences > Settings, will open a window with two documents, edit only the right, follow some settings you can use:
Removes unnecessary spaces when saving:
"trailing_spaces_trim_on_save": true,
Swap Tabs for spaces:
"translate_tabs_to_spaces": true,
Use Tabs as 4 spaces, you can adjust here:
"tab_size": 4,
Shows the encoding of the current file in the Sublimetext footer, helps avoid many headaches:
"show_encoding": true,
Line breaks use only LF
:
"default_line_ending": "unix",
Shows what type of "new line" you use, for example: Unix
(if the lines in the document end in LF
) or Windows
(if the lines in the document end in CR LF
):
"show_line_endings": true,
Add line break at the end of the document if necessary (of course this is optional):
"ensure_newline_at_eof_on_save": true,
It must look like this:
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"font_size": 11,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"indent_guide_options":
[
"draw_normal",
"draw_active"
],
"line_padding_bottom": 3,
"line_padding_top": 3,
"overlay_scroll_bars": "enabled",
"show_encoding": true,
"tab_size": 4,
"trailing_spaces_trim_on_save": true,
"translate_tabs_to_spaces": true,
"show_encoding": true,
"show_line_endings": true,
"ensure_newline_at_eof_on_save": true,
"word_wrap": true
}
Extra
Spell checker, there is no relation, but a spell checker can help avoid constraints sometimes, in case you can manually install it, which can be something very complex, I even tried to download the .dic
of Libreoffice and gave problem with Unicode, so I ended up copying .dic
that was in the Firefox folder, but this is a bit complicated, so I’ll tell you from the same repository, select the preferred language on https://github.com/titoBouzout/Dictionaries and download . dic and . Aff, for example:
Open the package folder, if it’s Linux or Mac:
~/.config/sublime-text-3/Packages
If it’s Windows maybe it’s the folder like this SublimeText\Data\Packages\
Create a folder called Portuguese
for example and copy both files in it, you may have to close the sublime and open again, so go to View > Dictionary and see if it shows up Portuguese
, or you can point to Settings as well, like this:
"dictionary": "Packages/Portuguese/Portuguese (Brazilian).dic",
And enable the spell checker permanently:
"spell_check": true,
It should look something like this:
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"dictionary": "Packages/Portuguese/Portuguese (Brazilian).dic",
"font_size": 11,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"indent_guide_options":
[
"draw_normal",
"draw_active"
],
"line_padding_bottom": 3,
"line_padding_top": 3,
"overlay_scroll_bars": "enabled",
"show_encoding": true,
"spell_check": true,
"tab_size": 4,
"trailing_spaces_trim_on_save": true,
"translate_tabs_to_spaces": true,
"show_encoding": true,
"show_line_endings": true,
"ensure_newline_at_eof_on_save": true,
"word_wrap": true
}
By default in Sublime, if you hold your mouse over the method name or variable it will display a popup with its declaration path, just click on the path and you’re done.
– Leonardo