1. 好用插件推荐
1.1 HtmlBeautify
html页面的美化,直接ctr+shift+p输入htmlB调用即可。
1.2 JsFormat
快捷方式ctr+alt+F,js的格式化。
1.3 SideBarEnhancements
增强的侧栏功能,添加就知道怎么好了
1.4 AdvancedNewFile
快捷方式ctr+alt+N,New新的文件,支持tab自动补全文件夹,非常方便。
1.5 SyncedSideBar
自动同步当前打开文件的side bar位置。
1.6 phpfmt(deleted)
直接安装就行。
https://packagecontrol.io/packages/phpfmt
注意确保php在系统的PATH中,因为这个功能具是php写的,需要php执行。
phpfmt已经商业化,需要使用免费的php-cs-fixer.phar作为engine,点击下载php-cs-fixer.phar拷贝到phpfmt的安装目录,更改phpfmt的settings,将engine更改为php-cs-fixer.phar。
另外,在Preferences----Package Settings----phpfmt----Settings - User中添加如下内容
{ "autocomplete": true, "autoimport": true, "passes": [ "AlignEquals", "AlignDoubleArrow", "AlignDoubleSlashComments", "AlignGroupDoubleArrow", "LongArray", ], "psr2": true, "smart_linebreak_after_curly": true, "version": 3 }
要执行,直接使用ctrl+shitf+p phpfmt: format now
。或者快捷键ctrl+f11
1.7 sublime_phpcs
这个是检查php代码错误的插件,推荐。
安装PHP_CodeSniffer:
pear : 下载 http://pear.php.net/go-pear.phar 执行: php go-pear.phar 执行:pear install PHP_CodeSniffer cpi ---安装package----> sublimilinter_phpcs
1.8 DocBlockr
sublime的php doc插件 DocBlockr,应该大家已经在用,现在需要修改一下配置,避免到处是[description]而实际上没有任何有效的description被添加的情况。
Preferences --> Package Settings --> DocBlockr -> Settings -User:
{ "jsdocs_function_description": false, "jsdocs_return_description": false, "jsdocs_param_description": false, "jsdocs_param_name": true, "jsdocs_align_tags": "shallow", "jsdocs_spacer_between_sections": true }
一个示例如下:
/** * Send wechat message and notice for purchasing order finished. * * @param App\Shop $shop * @param App\PurchasingOrder $purchasingOrder * * @return void */
注意
@param
后面有两个空格,而类型后面有一个空格,不需要对齐。- 方法说明后一个空行,
@param
块后一个空行。@return
后不允许有空行。
1.9 Cobalt2
这是一个color scheme,关注于把注意力放在代码本身,试用几个周后确实发现这种scheme有其优势。建议大家体验。
1.10 phpcs
因为phpfmt商业化导致无法正常使用,使用php-cs-fixer的engine也需要配置很多数据,建议使用phpcs
,配置如下:
- 使用composer安装php-cs-fixer
composer global require friendsofphp/php-cs-fixer
- sublime安装phpcs
pci------------- phpcs
- 配置phpcs,
preferences--package settings---php code sniffer
将以下内容添加进去:
{ // Example for: // - Windows 8.1 // - With phpcs and php-cs-fixer support // - You have to change "YOUR_USERNAME_HERE" strings. // - Notice: This uses phpcs which is installed // - using composer not xampp. // - Be sure to install phpcs using composer. // We want debugging on "show_debug": true, // Only execute the plugin for php files "extensions_to_execute": ["php"], // Do not execute for twig files "extensions_to_blacklist": ["twig.php"], // Execute the sniffer on file save "phpcs_execute_on_save": true, // Show the error list after save. "phpcs_show_errors_on_save": true, // Show the errors in the gutter "phpcs_show_gutter_marks": true, // Show outline for errors "phpcs_outline_for_errors": true, // Show the errors in the status bar "phpcs_show_errors_in_status": true, // Show the errors in the quick panel so you can then goto line "phpcs_show_quick_panel": true, // Path to php on windows installation // This is needed as we cannot run phars on windows, so we run it through php "phpcs_php_prefix_path": "", // We want the fixer to be run through the php application "phpcs_commands_to_php_prefix": ["Fixer"], // PHP_CodeSniffer settings // Yes, run the phpcs command "phpcs_sniffer_run": true, // And execute it on save "phpcs_command_on_save": true, // This is the path to the bat file when we installed PHP_CodeSniffer "phpcs_executable_path": "C:\\Users\\benjamincao\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcs.bat", // I want to run the PSR2 standard, and ignore warnings "phpcs_additional_args": { "--standard": "PSR2", "-n": "" }, // PHP-CS-Fixer settings // Don‘t want to auto fix issue with php-cs-fixer "php_cs_fixer_on_save": true, // Show the quick panel "php_cs_fixer_show_quick_panel": false, // The fixer phar file is stored here: "php_cs_fixer_executable_path": "C:\\Users\\benjamincao\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat", // Additional arguments, run all levels of fixing "php_cs_fixer_additional_args": { "--level":"psr2", "--fixers":"-psr0,array_element_no_space_before_comma,array_element_white_space_after_comma,extra_empty_lines,blankline_after_open_tag,duplicate_semicolon,function_typehint_space,operators_spaces,align_equals,align_double_arrow,ordered_use,whitespacy_lines,concat_with_spaces,unused_use,unary_operators_spaces,ternary_spaces,single_quote" }, // PHP Linter settings // Yes, lets lint the files "phpcs_linter_run": true, // And execute that on each file when saved (php only as per extensions_to_execute) "phpcs_linter_command_on_save": true, // Path to php "phpcs_php_path": "C:\\php-7.0.5-nts-Win32-VC14-x64\\php.exe", // This is the regex format of the errors "phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)", // PHP Mess Detector settings // Not turning on the mess detector here "phpmd_run": false, "phpmd_command_on_save": false, "phpmd_executable_path": "", "phpmd_additional_args": {"align_equals":""} }
注意:需要将路径配置为自己本地路径。
- 试一下是否正常。
2. 使用技巧
2.1 关于代码折叠:
ctrl+shift+[ 折叠代码块(光标所在位置) ctrlshift] 取消折叠(光标所在位置) ctrl+k,0 取消所有折叠 ctrl+k, 1 (-9) 设置折叠等级:1是类层面,2,就是类的所有函数了。 例如如果要将所有函数都折叠,可以这样操作:ctrl+k,2
php语法检测,sublime linter-php
打开控制台,install package
搜 sublimelinter
先安装sublimelinter本体
安装完以后再搜索一下,安装sublimelinter-php
接下来,打开preferences-package settings-sublimeLinter-settings--user
如下配置:
{ "user": { "linters": { }, "paths": { "linux": [], "osx": [], "windows": [ "D:\\xampp\\php" ] }, } }