vimでPHPの開発環境構築するときにしたこと

Webアプリエンジニア養成読本[しくみ、開発、環境構築・運用…全体像を最新知識で最初から! ] (Software Design plus)

Webアプリエンジニア養成読本[しくみ、開発、環境構築・運用…全体像を最新知識で最初から! ] (Software Design plus)

上記のムック第2章 「Webアプリケーション実践入門」PHPの演習をするにあたりvimの設定をいじったので備忘録。*1


vim標準のPHP用オプション
" 文字列中のSQLをハイライト
let php_sql_query           = 1
" Baselibメソッドのハイライト
let php_baselib             = 1
" 文字列中のHTMLをハイライト
let php_htmlInStrings       = 1
" <? をハイライト除外にする
let php_noShortTags         = 1
" カッコが閉じていない場合にハイライト
let php_parent_error_close  = 1
追加したプラグイン(PHP向け)
vim-twig

evidens/vim-twig
vimシンタックスハイライトは標準だとTwigテンプレートエンジンに対応しないので導入。 インストールはNeoBundleで一発。

NeoBundle 'evidens/vim-twig'

before

f:id:usadamasa:20150125222604j:plain

after

f:id:usadamasa:20150125222347j:plain

vim-php-cs-fixer

stephpy/vim-php-cs-fixer
コーディング規約に合致するかチェック、修正してくれるPHP Coding Standard Fixer*2vimから叩くプラグイン

" vim-php-cs-fixer {{{
NeoBundleLazy 'stephpy/vim-php-cs-fixer', {
\    'autoload' : {
\        'filetypes': 'php',},}
let s:hooks = neobundle#get_hooks('vim-php-cs-fixer')
function! s:hooks.on_source(bundle)
    let g:php_cs_fixer_level                  = 'all'                                " which level ?
    let g:php_cs_fixer_config                 = 'default'                            " configuration
    let g:php_cs_fixer_php_path               = 'php'                                " Path to PHP
    let g:php_cs_fixer_enable_default_mapping = 1                                    " Enable the mapping by default (<leader>pcd)
    let g:php_cs_fixer_verbose                = 1                                    " Return the output of command if 1, else an inline information.
endfunction
unlet s:hooks
"}}}

単独では動かずphp-cs-fixerを別途インストールする必要がある。homebrewで導入。

brew install homebrew/php/php-cs-fixer

なお、PHP自体もhomebrewで入れておくこと、php.iniのphar.readonly設定をOffにしておかないと警告が出て止まるので注意。

追加したプラグイン(PHP以外)
alignta

テキスト整形プラグインAlignの派生版。 ヘルプテキスト曰く、

alignta では、覚えることを少なくすること、「こう揃えたい」を1回のコマンドで実現できること、に重点がおかれています。

とのこと。 h1mesuke/vim-alignta

これまた導入にはNeoBundle。

NeoBundle 'h1mesuke/vim-alignta'

実行前後のdiffは以下。

f:id:usadamasa:20150125225802j:plain

変数代入の=を縦に整形 · b7618e6 · usadamasa/Tinitter