Vim syntax based folding with php

廉价感情. 提交于 2019-11-30 14:59:22

问题


I have downloaded php.vim file, which contains PHP-based syntax information. It should be able to provide syntax based folding, but I can't make it work for some reason.

I have set :let g:php_folding 2 and :set foldmethod=syntax but for no avail. I'm pretty sure the file is in right place and is read by vim, since I can do :let g:php_sql_query=1 which works.

The php.vim file is located in ~/.vim/syntax/php.vim


回答1:


:syntax enable (or :syntax on) work because both those options also turn on filetype detection. The filetype has to be detected before folding or highlighting work.

If you're developing in PHP you probably want to add these three lines to your .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.

Then you can put your let g:php_folding=2 and set foldmethod=syntax in your ~/.vim/after/ftplugin/php.vim file.

This will keep your .vimrc file clean, help organize all your settings, and the foldmethod=syntax will only affect php files (If you want to set syntax as your default fold method for all filestypes, leave that line in your .vimrc file)

For more detailed information read these help files:

:help filetype
:help usr_05.txt
:help usr_43.txt




回答2:


I find the phpfolding.vim , and it`s very easy to use.

  1. put the phpfolding.vim to $HOME/.vim/plugin/

  2. add keymap

    map <F5> <Esc>:EnableFastPHPFolds<Cr>

    map <F6> <Esc>:EnablePHPFolds<Cr>

    map <F7> <Esc>:DisablePHPFolds<Cr>

enjoy it!




回答3:


Apparently my VIM didn't run :syntax enable.

Doing :syntax enable fixed the problem, but I also added :syntax on to .vimrc



来源:https://stackoverflow.com/questions/792886/vim-syntax-based-folding-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!