:syntax enable(または:syntax on)は、これらのオプションの両方でファイルタイプの検出もオンにするため、機能します。折りたたんだり強調表示したりする前に、ファイルタイプを検出する必要があります。
PHPで開発している場合は、おそらくこれらの3行を.vimrcに追加する必要があります。
set nocompatible " Because filetype detection doesn't work well in compatible mode
filetype plugin indent on " Turns on filetype detection, filetype plugins, and filetype indenting all of which add nice extra features to whatever language you're using
syntax enable " Turns on filetype detection if not already on, and then applies filetype-specific highlighting.
let g:php_folding=2
次に、とset foldmethod=syntax
をファイルに入れることができ~/.vim/after/ftplugin/php.vim
ます。
これにより、.vimrcファイルがクリーンに保たれ、すべての設定が整理され、foldmethod = syntaxはphpファイルにのみ影響します(すべてのファイルタイプのデフォルトのfoldメソッドとして構文を設定する場合は、その行を.vimrcファイルに残します)
詳細については、次のヘルプファイルを参照してください。
:help filetype
:help usr_05.txt
:help usr_43.txt