vim 代码规范工具php-cs-fixer.phar
(参考https://github.com/FriendsOfPHP/PHP-CS-Fixer)
INSTALL
curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer
sudo chmod a+x php-cs-fixer
sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
至此,你可以直接用php-cs-fixer格式化代码了
USAGE
(目前支持的level有psr0, psr1, psr2,symfony,contrib)
php-cs-fixer fix test.php --level=psr2
php-cs-fixer fix ./ --level=psr2
这并不能满足一个vimer的小心灵
vim-php-cs-fixer
INSTALL
Bundle 'stephpy/vim-php-cs-fixer
CONFIGURE
.vimrc(参考:https://github.com/stephpy/vim-php-cs-fixer)
" If php-cs-fixer is in $PATH, you don't need to define line below
" let g:php_cs_fixer_path = "~/php-cs-fixer.phar" " define the path to the php-cs-fixer.phar
let g:php_cs_fixer_level = "psr2" " which level ?(psr0, psr1, psr2, symfony)
let g:php_cs_fixer_config = "default" " configuration
let g:php_cs_fixer_php_path = "php" " Path to PHP
" If you want to define specific fixers:
"let g:php_cs_fixer_fixers_list = "linefeed,short_tag,indentation"
let g:php_cs_fixer_enable_default_mapping = 1 " Enable the mapping by default (<leader>pcd)
let g:php_cs_fixer_dry_run = 0 " Call command with dry-run option
let g:php_cs_fixer_verbose = 0 " Return the output of command if 1, else an inline information.
以上配置我们发现
let g:php_cs_fixer_enable_default_mapping = 1 " Enable the mapping by default (<leader>pcd)
这个配置快捷键为\pcd 实际操作中会发现极易出错,而且太长了吧
.vim/bundle/vim-php-cs-fixer/plugin/php-cs-fixer.vim
if(g:php_cs_fixer_enable_default_mapping == 1)
nnoremap <silent><leader>pcd :call PhpCsFixerFixDirectory()<CR>
nnoremap <silent><leade