將PHP Manual融入(g)Vim

來源:互聯網
上載者:User

  • 作者: Laruence(    )
  • 本文地址: http://www.laruence.com/2010/08/18/1718.html
  • 轉載請註明出處

首先說個題外話: Vim發布7.3了..

在翻看Vim外掛程式的時候, 發現了一個比較有意思的應用(非外掛程式): 把PHP的手冊融如Vim中, 在Vim中, 按”K”, 就可以跳轉到游標下函數的手冊說明…

1. 首先, 下載特殊定製的PHP手冊(包含PHP5.3的所有函數) : vim-php-manual.tar.gz

2. 把下載的檔案解壓縮, 放置到一個目錄, 比如/tmp/phpmuanul(windows下比如:”d:/phpmanual”).

3. 配置vimrc(linux下是.vimrc,windows下是_vimrc), 把phpmanual目錄添加到runtimepath(稍後解釋為什麼).

4. 配置vimrc, 使得keywordprg=”help”. 在我的機器上, keywordprg預設是!man, 大多數時候, 我還是希望可以直接man到linux下的標準函數庫, 所以我使用(在vimrc檔案中):

<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; list-style-type: none; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; ">autocmd BufNewFile,Bufread *.ros,*.inc,*.php set keywordprg="help"</li></ol><p>

或者也可以寫在vim目錄下的ftplugin下的php.vim(如果沒有建立), 這樣在ft為php的時候,這個配置指令碼就會被載入.

至於說, 為什麼要把phpmanual目錄添加到runtimepath, 是因為:

<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; list-style-type: none; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; ">When no argument is given to :help the file given with the 'helpfile' option</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; ">will be opened. Otherwise the specified tag is searched for in all "doc/tags"</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; ">files in the directories specified in the 'runtimepath' option.</li></ol><p>

意思就是說, 在vim中, 調用help的時候, help會去所有的runtimpath下的doc目錄中尋找tags檔案, 來尋找要尋找的協助關鍵字.

在我們下載的vim-php-manual.tar.gz檔案中, 就包含了doc/tags這樣的檔案目錄結構, 所以只要把phpmanual目錄加入runtimepath, 並且設定keywordprg為vim的help, 就可以實現在游標處按”K”跳轉到函數手冊了.

使用

最後,補充一點, 如果在使用的時候,Vim提示你:

<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; list-style-type: none; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-style: inherit; font-size: 12px; font-family: inherit; vertical-align: baseline; "> tags file not sorted</li></ol><p>

那你就用vim開啟phpmanual/doc/tags, 然後%sort一下就可以了…

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.