基于 Vim 语法的 PHP 折叠

发布于 2024-07-17 15:18:47 字数 321 浏览 4 评论 0原文

我已经下载了 php.vim 文件,其中包含基于 PHP 的语法信息。 它应该能够提供基于语法的折叠,但由于某种原因我无法使其工作。

我已经设置了 :let g:php_folding 2:set Foldmethod=syntax 但没有效果。 我很确定该文件位于正确的位置并且由 vim 读取,因为我可以执行 :let g:php_sql_query=1 ,它可以工作。

php.vim 文件位于 ~/.vim/syntax/php.vim

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜唯美灬不弃 2024-07-24 15:18:47

:syntax enable (或 :syntax on)有效,因为这两个选项也会打开文件类型检测。 在折叠或突出显示工作之前必须检测文件类型。

如果您使用 PHP 进行开发,您可能需要将这三行添加到您的 .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=2set Foldmethod=syntax 放入你的 ~/.vim/after/ftplugin/php.vim 文件。

这将使您的 .vimrc 文件保持干净,帮助组织所有设置,并且 Foldmethod=syntax 只会影响 php 文件(如果您想将语法设置为所有文件类型的默认折叠方法,请将该行保留在您的 .vimrc 文件中)

有关更多详细信息,请阅读这些帮助文件:

:帮助文件类型
:help usr_05.txt
:help usr_43.txt

: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

隐诗 2024-07-24 15:18:47

我找到了 phpfolding.vim ,它非常容易使用。

  1. 将 phpfolding.vim 放入 $HOME/.vim/plugin/

  2. < p>添加键盘映射

    地图:EnableFastPHPFolds

    地图:EnablePHPFolds

    地图:DisablePHPFolds

尽情享受吧!

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!

白昼 2024-07-24 15:18:47

显然我的 VIM 没有运行 :syntax enable。

执行 :syntax enable 解决了问题,但我还在 .vimrc 上添加了 :syntax

Apparently my VIM didn't run :syntax enable.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文