Vim 快速補齊 PHP function 名稱

使用 IDE 介面大多數都會有自動補齊 Function 等功能, 那 Vim 寫 PHP 時該如何達到相同的事呢?

首先需要一個字典檔, 就是 PHP 所有 function 的列表: PHP: Manual Quick Reference

於這頁只要滑鼠選取後, 就可以得到 funclist.txt (funclist.txt.gz 這是存好的, 可直接下載解壓縮後, 直接取用)

funclist.txt 內容

funclist.txt 內容就是每個 function-name 都獨立一行, ex:

abs
acos
acosh
addcslashes
addslashes
...

設定步驟

  1. 取得 funclist.txt
  2. 將 funclist.txt 放到 ~/.vim 內. (mv funclist.txt ~/.vim)
  3. 設定 ~/.vimrc

    set dictionary-=~/.vim/funclist.txt

在寫 PHP 時, 就可以 Ctrl + p / Ctrl + n 達成 Function 自動補齊的功能囉~

註: 輸入 my 後, 直接 Ctrl + p 就可以上下選, Enter 就會自動將選取的補齊.

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

在〈Vim 快速補齊 PHP function 名稱〉中有 12 則留言

  1. 恩 content 沒貼到
    /* comment */ function xxx()
    {
    print okok;
    }
    要是這樣的話...用vim 去indent 的話會有問題
    我昨天有email 給php.vim 的作者..
    回應如下
    Hello,
    Comments in front of function declarations (or at start of lines in general) are currently not supported by the php indent script.
    I may add support for it but it will depends on the resulting impact on speed... (stripping comments of every line to analyze may reduce indentation speed by a big factor.)
    John
    在等看看囉
    我自已是先把/usr/local/share/vim72/indent/php.vim
    先拿掉了

  2. 嗯嗯, 這做法蠻不錯的.
    可以自動更新來產生這個檔案, 而且其它 function 也很棒~ 😀
    get_defined_constants, get_defined_functions, get_declared_interfaces, get_declared_classes, get_extension_funcs, get_class_methods, spl_classes.
    非常有用, 之後測試後再整理寫一寫, 感恩~ Orz..

  3. 如果是 ditionary completion 用 C-x C-k 就可以了。 會比 C-n,C-p 來得快。(因為 C-n,C-p 是做 global 搜尋 )
    我記得 php 的 function completion 已經有人寫 plugin 了。

johnpupu 發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料