DEV Community

Discussion on: What Is PHP CS Fixer and How It Can Help You Keep Your Code Cleaner

Collapse
 
gbhorwood profile image
grant horwood

setting up cs fixer in vim is pretty straightforward:

install the phar locally

git clone https://github.com/stephpy/vim-php-cs-fixer.git ~/.vim/pack/plugins/start/vim-php-cs-fixer
curl -L https://cs.symfony.com/download/php-cs-fixer-v2.phar -o ~/.vim/php-cs-fixer.phar
chmod 755  ~/.vim/php-cs-fixer.phar
Enter fullscreen mode Exit fullscreen mode

then in your .vimrc

"-------------------------------
" php-cs-fixer config
" <F4> fix
let g:php_cs_fixer_path = "~/.vim/php-cs-fixer.phar"
let g:php_cs_fixer_rules = "@PSR2"
let g:php_cs_fixer_php_path = "/usr/bin/php"
map <F4> :call PhpCsFixerFixFile()<CR>
Enter fullscreen mode Exit fullscreen mode

obviously, you can change the hotkey or the ruleset.