VSCode安装php格式化工具php formatter
项目地址:https://marketplace.visualstudio.com/items?itemName=Sophisticode.php-formatter
Vscode插件安装命令
ext install php-formatter
新版本已经取消ext命令了,直接在插件面板搜索即可:php-formatter
该插件需要php-cs-fixer.phar
https://github.com/FriendsOfPHP/PHP-CS-Fixer。
所以安装步骤如下:
0.你的电脑有php
运行环境,而且你知道php.exe
文件的位置在哪。
1.下载 php-cs-fixer.phar
,我直接把它和php.exe放在同一个目录。
2.打开VS Code
,摁下F1
,清空内容,输入ext install php-formatte
执行安装
3.打开 文件->首选项->用户设置,在右侧设置文件内添加
1 2 3 4 5 6 7 8 9 |
"phpformatter.composer": false, // Should point to php-cs-fixer.phar file, if you have installed this manually (without Composer). Should include .phar extension. "phpformatter.pharPath": "E:/wamp/bin/php/php7.0.4/php-cs-fixer.phar", // If the pharPath is set, and you are not using Composer, and you haven't added PHP to your PATH, this should point to the php.exe file. "phpformatter.phpPath": "E:/wamp/bin/php/php7.0.4/php.exe" |
4.绑定快捷键
打开 文件->首选项->键盘快捷方式,在右侧设置文件内添加
1 2 3 4 5 |
{ "key": "ctrl+alt+f", "command": "phpformatter.fix", "when": "editorTextFocus" } |
我这里用的是Ctrl+alt+f
.因为和一个html
格式化插件的快捷键冲突了
vs 1.38 根本找不到,垃圾,坑
直接插件面板搜索php-formatter即可