Format PHPFmt, Delete Blank Lines (ok)
CTRL + F11
DOCUMENTATION Indentation Settings 😁
C:\Users\Administrator\AppData\Roaming\Sublime Text\Packages\User\Default (Windows).sublime-keymap (Sử dụng Key Benddings)

[
{ "keys": ["ctrl+shift+i"], "command": "reindent" }
]
Chú ý: FMT trong visual studio code cấu hình php xam như sau :)
{
"workbench.startupEditor": "newUntitledFile",
"[php]": {
"editor.defaultFormatter": "kokororin.vscode-phpfmt"
},
"editor.tabSize": 2,
"phpfmt.php_bin": "C:\\xampp\\php\\php.exe",
"phpfmt.psr2": false,
"phpfmt.indent_with_space": 2,
"phpfmt.detect_indent": false,
"phpfmt.enable_auto_align": true,
"php.validate.executablePath": "C:\\xampp\\php\\php.exe"
}
Xem ảnh dưới để điều chỉnh phù hợp :)

Quy trình format code đẹp không có dòng trống (ok)
Bước 1:
Vô page: https://www.tutorialspoint.com/online_php_formatter.htm để là remove spaces
Kết hợp với: http://beautifytools.com/php-beautifier.php để format tab = 2

Bước 2:
Copy code bô visual studio code (sử dụng f1 + phpfmt: this file)

Bước 3: Copy thành quả :)
Với Ampps
{
"enable_auto_align": true,
"format_on_save": false,
"identation": 2,
"indent_with_space": 2,
"option": "value",
"passes":
[
"ReindentSwitchBlocks",
"OrderAndRemoveUseClauses",
"PSR2EmptyFunction",
"StripSpaceWithinControlStructures",
"ShortArray",
"AutoSemicolon"
],
"php_bin": "C:/Program Files/Ampps/php/php.exe",
"psr1": false,
"psr2": false,
"version": 4
}
{
"version": 4,
//"php_bin":"/usr/local/bin/php",
"indent_with_space": false,
// "enable_auto_align": true,
<?php
// $a = 10;
// $otherVar = 20;
// $third = 30;
// Thanh
// <?php
// $a = 10;
// $otherVar = 20;
// $third = 30;
"enable_auto_align": true,
"format_on_save":false,
"option": "value",
"psr2": true,
}
Trong windows
{
"version": 4,
"psr1":false,
"psr2":false,
"php_bin":"C:/xampp/php/php.exe",
"indent_with_space": 2,
"enable_auto_align": true,
"passes":
[
"ReindentSwitchBlocks",
"OrderAndRemoveUseClauses",
"PSR2EmptyFunction",
"StripSpaceWithinControlStructures",
"ShortArray",
"AutoSemicolon"
],
"format_on_save":true,
"identation": 2,
"option": "value"
}
Hoặc chuẩn hơn
{
"enable_auto_align": true,
"format_on_save": false,
"identation": 2,
"indent_with_space": 2,
"option": "value",
"passes":
[
"OrderAndRemoveUseClauses",
"PSR2EmptyFunction"
],
"php_bin": "C:/xampp/php/php.exe",
"psr1": false,
"psr2": false,
"version": 4
}
Link:
https://stackoverflow.com/questions/9645545/how-to-determine-path-to-php-exe-on-windows-search-default-paths
Ubuntu
"phpfmt.php_bin": "/usr/bin/php"
Và để cài đặt xóa khoảng trắng luôn ta dùng:
/home/lionel/.config/sublime-text/Packages/User/Default (Linux).sublime-keymap
[
{
"command": "delete_blank_lines",
"args": { "surplus": true },
"keys": [
"ctrl+f11"
]
},
{
"command": "delete_blank_lines",
"args": { "surplus": false },
"keys": [
"ctrl+f11"
]
}
]
Hoặc
[
{
"command": "delete_blank_lines",
"args": { "surplus": true },
"keys": [
"f11"
]
},
{
"command": "delete_blank_lines",
"args": { "surplus": false },
"keys": [
"f11"
]
}
]
Đối với lampp 7.3.10 thì chúng ta vào theo cách sau (ok)
{
"version": 4,
"php_bin":"/opt/lampp/bin/php",
"indent_with_space": true,
//This can be enabled with the option “enable_auto_align”
"enable_auto_align": true,
"format_on_save":false,
"option": "value"
}
{
"version": 4,
"php_bin":"/opt/lampp/bin/php",
// Note the identation of 2 spaces.
"indent_with_space": 2,
"enable_auto_align": true,
"format_on_save":false,
"option": "value"
}
{
"version": 4,
//"psr1":true function add_count($slug) => function addcount($slug)
"psr1":false,
"psr2":true,
// "psr2":true function add_count($slug) {
// }
// Convert to
// function add_count($slug)
// {
// }
"php_bin":"/opt/lampp/bin/php",
"indent_with_space": 2,
"enable_auto_align": false,
"format_on_save":false,
"identation": 2,
"option": "value"
}
<?php
for ($i = 0; $i < 10; $i++) {
if ($i % 2 == 0) {
echo "Flipflop";
}
// Đây là khoản trống trông rất khó chịu
}
chuyển thành
<?php
for ($i = 0; $i < 10; $i++) {
if ($i % 2 == 0) {
echo "Flipflop";
}
}
Chú ý:
Tham số "StripSpaceWithinControlStructures",
{
// "autocomplete": true,
// "autoimport": true,
// "enable_auto_align": false,
"format_on_save": true,
// "ignore": "Parent",
"indent_with_space": 2,
"passes":
[
// "ReindentSwitchBlocks",
// "OrderAndRemoveUseClauses",
// "PSR2EmptyFunction",
"StripSpaceWithinControlStructures",
// "ShortArray",
// "SpaceBetweenMethods",
// "AutoSemicolon"
],
"php_bin": "/opt/lampp/bin/php",
"psr2": true,
"smart_linebreak_after_curly": true,
"version": 4,
"visibility_order": true,
"yoda": true
}
Bản chuẩn
{
"version": 4,
"psr1":false,
"psr2":true,
"php_bin":"/opt/lampp/bin/php",
"indent_with_space": 2,
"enable_auto_align": true,
"passes":
[
"ReindentSwitchBlocks",
"OrderAndRemoveUseClauses",
"PSR2EmptyFunction",
"StripSpaceWithinControlStructures",
"ShortArray",
"AutoSemicolon"
],
"format_on_save":true,
"identation": 2,
"option": "value"
}
Toàn bộ cấu hình Sublime Text Configuration for PHP
https://gist.github.com/torniker/0e00593cbc1f12bed511
Sublime Text is a powerful text editor , its not just a text editor compare to other text editor the plug-ins of sublime text enables it to a complete IDE options. Here I will tell you the basic configuration required for PHP development using sublime text.
Sublime Text Configuration for PHP have the following main plug-ins.
PHPfmt
Sublime linter
Sublime Linter – PHP
Bracket highlighter
HTML beautify.
Git Gutter
Alignment
There are many other useful plug-ins available for Sublime text. First of all install the Sublime text latest version on your system based on your OS Win/Linux. Once you installed the Sublime Text good to go with package Controller. You have to run the Python code provided by the package controller io. Based on Sublime text version choose the script code. Open your console with Ctrl+` Paste the code and press enter. once it render you may need to restart the Sublime Text, It will install the required dependency as well.
Now you will be able to install other plug-ins packages via pressing Ctrl + Shift + P . then type ” install ” it will load all the repository for you the just type the above list of plug-ins name one by one .
Once you install all the required list now you can configure each of the plug-ins with you customization.PHPfmt Configuration
Open the Preference menu of sublime text -> Package Settings -> PHPfmt-> user Settings. Paster the following codes.
{
"disable_auto_align": true,
"format_on_save": false,
"indent_with_space": false,
"passes":
[
],
"php_bin": "/usr/bin/php",
"psr1": true,
"psr2": true,
"version": 3
}
make sure your PHP installation path is correct. Now you can set the short for formatting the phpfmt output Preference -> Key Binding – User paster the following codes.
[
{
"keys": ["alt+shift+c"],
"command": "fmt_now"
}
]
I set it to alt+shift+c you can set it to your own key combination. Sublime linter
This is an awesome plug-in that helps to detect PHP syntax errors while you coding.
Open Preference -> Package Settings -> Sublime Linter -> User Settings.
{
"user": {
"debug": true,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/User/SublimeLinter/Monokai Bright (SL).tmTheme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"php": {
"@disable": false,
"args": [],
"excludes": []
},
"phplint": {
"@disable": false,
"args": [],
"excludes": []
}
},
"mark_style": "outline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [
"/usr/bin/php"
],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": true,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"php": "html",
"python django": "python"
},
"warning_color": "DDB700",
"wrap_find": true
}
}
You can set the basic theme and spacing of tab index and all with following code. add the code inside your Preference -> User Settings
{
"auto_complete": true,
"auto_complete_delay": 0,
"bold_folder_labels": true,
"close_windows_when_empty": false,
"color_scheme": "Packages/User/SublimeLinter/Monokai Bright (SL).tmTheme",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"find_selected_text": true,
"fold_buttons": true,
"folder_exclude_patterns":
[
".svn",
".hg",
"CVS",
"_build",
"dist",
"build",
"site",
"report",
"node_modules",
],
"font_face": "Ubuntu Mono",
"font_options":
[
"subpixel_antialias"
],
"font_size": 12,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
Forced refresh of the Project folder can be set with short cut key combination add the following code inside your User key binding.
{ "keys": ["ctrl+f7"], "command": "refresh_folder_list" }
here also the make sure the php path is correct as well, I’m on Linux machine so settings are are according to that.
If you preferred more package for JS and CSS like Js beautify or Less and Sass support etc are also available in Sublime Text Package repo.
Hope this article will help you to set up the PHP coding standard with PSR-2 using Sublime Tex
Delete Blank Lines
https://packagecontrol.io/packages/DeleteBlankLines
Windows: - Ctrl+Alt+Backspace –> Delete Blank Lines - Ctrl+Alt+Shift+Backspace –> Delete Surplus Blank Lines
OSX: - Fn+Ctrl+Option+Delete –> Delete Blank Lines - Fn+Ctrl+Option+Shift+Delete –> Delete Surplus Blank Lines
Linux: - Ctrl+Alt+Backspace –> Delete Blank Lines - Ctrl+Alt+Shift+Backspace –> Delete Surplus Blank Lines
Last updated
Was this helpful?