标题:[实践OK]Sublime Text 3 配置 PHPCS 插件:2016 正确 sublime安装PHPcs PHPcodesniffer代码规范提示插件,修正网上部分不详细描述,ctags。 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Fri, 12 Aug 2016 13:35:27 +0000 作者:jackxiang 地址:http://jackxiang.com/post/8881/ 内容: 有用的插件: SublimeCodeIntel 让sublime跳转到变量定义的地方: http://www.xuebuyuan.com/1122417.html 需要在用户目录添加配置文件。linux就是创建 ~/.codeintel/config 文件,具体readme,win也是用户目录下 sublimecodeintel 安装后需要配置,文件:插件目录/.codeintel/config 中 增加 "PHP": { "php": 'D:\SaeServer\php\php.exe', "phpExtraPaths": ['D:\SaeServer\php\stdlib'], "phpConfigFile": 'D:\SaeServer\apache\php.ini' }, { "PHP": { "php": 'D:\\wamp2\\bin\\php\\php5.3.13\\index.php', "phpExtraPaths": [D:\\www\\jackxiang.com], "phpConfigFile": 'D:\\wamp2\bin\\php\\php5.3.13\\php.ini' }, "JavaScript": { "javascriptExtraPaths": [] }, "Perl": { "perl": "/usr/bin/perl", "perlExtraPaths": [] }, "Ruby": { "ruby": "/usr/bin/ruby", "rubyExtraPaths": [] }, "Python": { "python": '/usr/bin/python2.7', "pythonExtraPaths": [] } } ctags。 这个插件能跨文件跳转,跳转到指定函数声明的地方。 使用package control 搜索ctags 进行安装(安装ctags插件就可以了, 还有一个 CTags for PHP 插件没什么用)。注意安装好插件后要需要安装ctags命令。window 下载 ctags.exe http://vdisk.weibo.com/s/7QZd7 。 将ctags.exe文件放在一个环境变量能访问到的地方。打开cmd, 输入ctags,如果有这个命令,证明成功了。 ubuntu下安装运行命令:sudo apt-get install exuberant-ctags 。 然后在sublime项目文件夹右键, 会出现Ctag:Rebuild Tags 的菜单。点击它,然后会生成.tags的文件。也可: ctags -R -f .tags生成 .tags文件,然后在sublime下就可以用ctrl+t ctrl+t来跳转,用ctrl+t ctrl+b来返回到原来位置。 From:http://www.cnblogs.com/cchun/p/3794018.html ctags 生成.ctags ctrl + t + r 同时t r。 跳转到声明 ctrl + t + t ,ctrl+> ,ctrl+shift+left_click (按两次t,> 这个在笔记本键盘上得按下shift上档键的点上面才有> ,ctrl+shift+.) 返回 ctrl + t + b ,ctrl+< ,ctrl+shift+right_click (t b两次,或直接按ctrl+shift+,), ,这个就是, 上面的<符号。 sublime配置全攻略: http://blog.csdn.net/w6611415/article/details/7725566/ 以下来处:http://www.cnblogs.com/lchg/p/5304168.html 对你有助请点赞,请顶,不好请踩------送人玫瑰,手留余香! 目录放错地了是关键,目录在:D:\Program Files\sublime\Data\Packages\sublime-phpcs-master ,win7好像真没有这个目录。 C:\Users\admin\AppData\Roaming\Sublime Text 3\Packages 放这儿才是: "D:\Program Files\SublimeText3\Data\Packages\User\phpcs.sublime-settings" 但是window10的sublime路径的确在: { // Example for: // - Windows 7 // - With phpcs and php-cs-fixer support // 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": "D:\\wamp\\bin\\php\\php5.3.13\\php.exe", // 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": "D:\\wamp\\bin\\php\\php5.3.13\\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": false, // Show the quick panel "php_cs_fixer_show_quick_panel": true, // The fixer phar file is stored here: "php_cs_fixer_executable_path": "D:\\wamp\\bin\\php\\php5.3.13\\php-cs-fixer.phar", // Additional arguments, run all levels of fixing "php_cs_fixer_additional_args": { }, // 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": "D:\\wamp\\bin\\php\\php5.3.13\\php.exe", // This is the regex format of the errors "phpcs_linter_regex": "(?P.*) on line (?P\\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": { "codesize,naming,unusedcode": "" } } ------------------- 14:37 2016/3/21 2016 正确 sublime安装PHPcs PHPcodesniffer代码规范提示插件,修正网上部分不详细描述 插曲:我之前安装过好多次,用命令安装过一次,放过一个phpcs的安装包在我的sublime安装包路径下一次,今天根据网上又放了一个安装包,发现sublime的preference有3个phpcodesnifer,但是都不能执行成功,最后删除了两个安装包,在再命令行中remove了那个用命令安装的,然后重新如下进行了安装! 注意我有两个地方和网上不一样才成功了! 按照下面的步骤完成后鼠标右键,选择codesniffer this fill,上方和代码左侧就会有相应的提示了 操作过程如下: 第一步:下载php code sniffer插件安装包 地址 https://github.com/benmatselby/sublime-phpcs; 解压安装包得到sublime-phpcs-master,把sublime-phpcs-master文件夹放到sublime安装目录下的Data/Packages/目录下; 特别注意:我的是windows,我的packages并不在sublime的安装路径下,我的在:C:\Users\super\AppData\Roaming\Sublime Text 3\Packages。我的sublime目录下有一个packages文件夹,之前一直放在那里面打开并没有显示下面的效果,后来在preference下的browse packages我猜想起来为什么这里面的几个插件文件夹在sublime那个文件夹下面并没有显示呢,才发现原因!! 重启sublime, 打开Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer 证明插件安装成功; 第二步:下载php-cs-fixer.phar 地址 http://cs.sensiolabs.org/get/php-cs-fixer.phar ; 第三步:把php-cs-fixer.phar 放到你的 php.exe 安装目录 (例如(mine is C:/WAMP/php/php.exe)); 特别注意:下面这里有错,我直接把这个安装包放到自己的一个目录下,在下面修改配置的时候按照它这个配置始终没能执行成功,想来想来弄了一下午,租后觉得只把下面这个的phpcs.bat放到php.exe 安装目录下不合理,其他文件都没用到呢,最后直接把后面的那个配置改成了我放置的路径就执行成功了:"phpcs_executable_path": "E:\\my_install_packages\\PHP_CodeSniffer-2.4.0\\PHP_CodeSniffer-2.4.0\\scripts\\phpcs.bat", 并没有把那个文件单独拿出放到php的执行路径下。 以此类推:我猜另外的一个也可以放到其他位置,修改配置即可,我修改确实实践成功(不知道跟我把php执行路径加入到windows的环境变量有无关系):"php_cs_fixer_executable_path": "C:\\wamp\\bin\\php\\php5.4.12\\php-cs-fixer.phar",改成:"php_cs_fixer_executable_path": "E:\\my_install_packages\\php-cs-fixer.phar", 第四步:下载 http://download.pear.php.net/package/PHP_CodeSniffer-1.5.0RC4.tgz,解压,然后找到scripts目录下的phpcs.bat,放到php.exe 安装目录; 第五步:解压打开 第一步下载的php code sniffer安装包,在子文件example-settings下有个文件 windows-7-phpcs-fixer-linter.example 就是Sublime Text 3 在windows7配置 PHPCS 的样例,还有一个nix-all-commands.example是在linux/unix环境下的配置样例 第六步:以下就是windows-7-phpcs-fixer-linter.example的配置内容,打开你的Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer -> Settings - User ,复制 windows-7-phpcs-fixer-linter.example 的内容到配置文件phpcs.sublime-settings,然后修改对应的php.exe路径 设置都改成你本地环境下的php安装路径,保存,重启Sublime Text 3 { // 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": "C:\\wamp\\bin\\php\\php5.4.12\\php.exe", // This is the path to the bat file when we installed PHP_CodeSniffer "phpcs_executable_path": "C:\\wamp\\bin\\php\\php5.4.12\\phpcs.bat", // PHP-CS-Fixer settings // Don't want to auto fix issue with php-cs-fixer "php_cs_fixer_on_save": false, // Show the quick panel "php_cs_fixer_show_quick_panel": true, // The fixer phar file is stored here: "php_cs_fixer_executable_path": "C:\\wamp\\bin\\php\\php5.4.12\\php-cs-fixer.phar", // 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:\\wamp\\bin\\php\\php5.4.12\\php.exe", // This is the regex format of the errors "phpcs_linter_regex": "(?P.*) on line (?P\\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": {} } 重启Sublime Text 3,打开php程序,语法错误提示如下图: 参见:http://my.oschina.net/qsmoon/blog/280813 Generated by Jackxiang's Bo-blog 2.1.1 Release