星期日, 八月 05, 2007

Vim 設定 foldmethod for PHP

Vim 只要 {{{ 和 }}} 包起來, 就會自動折合 fold 的動作, 但是不知何時開始, 在 php 裡面的 fold 動作都沒用了, 花了點時間研究怎麼再弄出來(.vimrc 設了都不理我, 但是在 .vimrc 裡面使用 {{{,}}} 都還是有用. :~)

Fold 的動作快速鍵:

  • zo: Open Fold
  • zc: Close Fold 
  • zm: 全部縮起來(將 foldlevel-1)
  • zM: 全部縮起來(設 foldlevel=0)
  • zf: 製作出起始 Fold 符號
  • zF: 製作出起始與結尾 Fold 符號

照理說是 .vimrc 設下述兩行就可以用.

  • set foldmarker={{{,}}}
  • set foldmethod=marker
  • set foldlevel=0 " 預設全部關閉

但是 PHP 不行(預設 php.vim 設的 foldmethod=syntax, 但是又吃不到 .vimrc 設的 foldmethod), 然後在 .vim/syntax/php.vim 直接寫這兩行也不行, 最後的解法如下:

  1. 先把預設的 php.vim cp 過來, 然後再於最下方加上這幾個設定.
  2. cp /usr/share/vim/vim71/syntax/php.vim ~/.vim/syntax/php.vim
  3. vim ~/.vim/syntax/php.vim # 於檔案最下方加入下面兩行
    set foldmarker={{{,}}} " 可省略, marker 預設就是 {{{,}}}
    set foldmethod=marker
    set foldlevel=0 " 預設全部關閉
  4. 順便再多加一行 hi Comment term=standout cterm=bold ctermfg=0
  5. 最近註解喜歡看黑色 XD

這樣子就收工囉~ 開個檔案弄一行 {{{, 再換行打 }}}, 然後 zc 看看會不會合起來就知道成功失敗囉~ :P

更多詳細可參考:

 

相關標籤

this is comment icon [回覆]

PHP 直接內建 fold

:let php_folding = 1

from syntax.txt

Comment by Cornelius (08/06/2007 03:46)

this is comment icon [回覆]

:set foldmethod=marker
設這行就可以了,因為 marker 預設就是 {{{,}}}

Comment by Cornelius (08/06/2007 03:49)

this is comment icon 回 Cornelius [回覆]

嗯嗯~ let php_folding = 1 我也有試過, 設在 php.vim 最上面. php.vim 上面註解說明是這樣, php_folding = 1 for folding classes and functions php_folding = 2 for folding all { } regions 然後發現只要有 { } 就會變 folding, 反而縮的過多了, 所以才覺得應該另外自己設~ 原來 marker 預設是這個.. 感謝指點~ Orz...
Comment by Tsung (08/06/2007 10:36)

this is comment icon [回覆]

那可以考慮試試看

:set foldnestmax=2

這樣就最多兩層 fold ,挺合用的。 :)

Comment by Cornelius (08/06/2007 14:08)

this is comment icon 回 Cornelius [回覆]

感恩~ 很好用 :D
而且剛剛又看到 http://man.chinaunix.net/newsoft/vi/doc/fold.html 這篇說明~
真棒 :D

Comment by Tsung (08/06/2007 14:42)

this is comment icon [回覆]

覺得我們台灣是不是也來翻個繁體中文版 :P

Comment by Cornelius (08/07/2007 02:35)

this is comment icon 回 Cornelius [回覆]

哈~ 大大的意思是, 簡繁轉換一下, 再修一下詞? :P

Comment by Tsung (08/07/2007 10:41)

this is comment icon [回覆]

重翻會不會好很多ar? XDD

# 我只是鄉民 :P

Comment by Cornelius (08/07/2007 19:48)

this is comment icon 回 Cornelius [回覆]

這...... 會不會太衝動???.....
同樣都是中文, 應該轉成繁體再修改一下語句應該就好了吧 XDDDD.

Comment by Tsung (08/07/2007 22:42)
Add this page to del.icio.us Add this page to Yahoo Taiwan's bookmark Add this page to MyShare

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~