vim php代码规范

本文介绍了如何在vim中使用php-cs-fixer工具来遵循PHP代码规范,包括安装、使用以及自定义快捷键的方法,特别提到了psr0到psr2等不同的规范级别。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值