星期三, 三月 18, 2009

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 就會自動將選取的補齊.

相關標籤

this is comment icon johnpupu [回覆]

我在vim 有設定autocomplete
按tab 觸發
看起來也可以自動補齊
php function

以下是ref link
給tsung 大參考
http://wiki.geckos.cn/index.php/Vim%E4%B8%AD%E7%9A%84%E4%BB%A3%E7%A0%81%E8%A1%A5%E5%85%A8
http://blog.othree.net/log/vim/

Comment by johnpupu (03/18/2009 09:09)

this is comment icon 回 johnpupu [回覆]

感恩, 真是方便的 Plugin, 我取用這兩個~
SuperTab: 用 Tab 就可以不用 Ctrl + p / n.
http://www.vim.org/scripts/script.php?script_id=1643
autocomplpop.vim: 自動列出所有相關的字 (有時後會有點卡卡的)
http://www.vim.org/scripts/script.php?script_id=1879

Comment by Tsung (03/18/2009 10:52)

this is comment icon johnpupu [回覆]

^^
對了 突然想到
想請教一下Tsung 大

這樣大大在縮排的時後會不會都沒什麼作用了

Comment by johnpupu (03/18/2009 12:33)

this is comment icon 回 johnpupu [回覆]

不會耶, 還是好好的阿. @.@a..

Comment by Tsung (03/18/2009 22:53)

this is comment icon indent [回覆]

恩 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
先拿掉了

Comment by johnpupu (03/19/2009 12:28)

this is comment icon johnpupu [回覆]

jon

我用的不是他的, 但是我也忘記從哪邊找來的了..
我寄給您, 您試試看~ :)

Comment by Tsung (03/19/2009 13:12)

this is comment icon 自動查詢function用法 [回覆]

我記得有內建這一個...
是按哪兩個按鍵我忘了說!

Comment by Girvan (03/21/2009 07:56)

this is comment icon 回 Girvan [回覆]

應該是 Ctrl + p / Ctrl + n, 不過應該都需要有字典檔.
我猜是您的 php.vim 有含這些?

Comment by Tsung (03/21/2009 11:21)

this is comment icon [回覆]

雖然我沒用Vim,但這邊分享我製作字典檔的方法,一波三折呀/__\

http://doublekai.org/blog/?p=563

原來只要很單純的語法就可以製作出來的可以用PHP語法產生字典檔

Comment by sankai (03/21/2009 22:32)

this is comment icon 回 sankai [回覆]

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

Comment by Tsung (03/21/2009 22:42)

this is comment icon [回覆]

如果是 ditionary completion 用 C-x C-k 就可以了。 會比 C-n,C-p 來得快。(因為 C-n,C-p 是做 global 搜尋 )

我記得 php 的 function completion 已經有人寫 plugin 了。

Comment by c9s (03/26/2009 10:35)

this is comment icon 回 c9s [回覆]

耶, 但是 C-x C-k 我試不行耶.
plugin 我剛剛直接找是沒看到, 不過找到這個:
http://vim.wikia.com/wiki/PHP_manual_in_Vim_help_format
看起來好像也是類似的功能. :P

Comment by Tsung (03/26/2009 10:43)
Add this page to del.icio.us

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


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