Press "Enter" to skip to content

将PHP Manual融入(g)Vim

首先说个题外话: 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文件中):

autocmd BufNewFile,Bufread *.ros,*.inc,*.php set keywordprg="help"

或者也可以写在vim目录下的ftplugin下的php.vim(如果没有新建), 这样在ft为php的时候,这个配置脚本就会被加载.
至于说, 为什么要把phpmanual目录添加到runtimepath, 是因为:

When no argument is given to :help the file given with the 'helpfile' option
will be opened.  Otherwise the specified tag is searched for in all "doc/tags"
files in the directories specified in the 'runtimepath' option.

意思就是说, 在vim中, 调用help的时候, help会去所有的runtimpath下的doc目录中寻找tags文件, 来寻找要查找的帮助关键字.
在我们下载的vim-php-manual.tar.gz文件中, 就包含了doc/tags这样的文件目录结构, 所以只要把phpmanual目录加入runtimepath, 并且设置keywordprg为vim的help, 就可以实现在光标处按"K"跳转到函数手册了.

使用截图

最后,补充一点, 如果在使用的时候,Vim提示你:

 tags file not sorted

那你就用vim打开phpmanual/doc/tags, 然后%sort一下就可以了...

37 Comments

  1. jual wire mesh di bekasi
    jual wire mesh di bekasi March 27, 2015

    There is certainly a lot to find out about this
    issue. I really like all the points you have made.

  2. grow lights
    grow lights September 23, 2014

    Everything published made a ton of sense. However, what about this?
    what if you wrote a catchier title? I am not saying your information is
    not solid, however what if you added a title that makes people desire more?
    I mean 将PHP Manual融入(g)Vim | 风雪之隅 is kinda
    vanilla. You should peek at Yahoo’s home page and note how they
    create article headlines to grab viewers to click.
    You might add a related video or a pic or two to get people interested about what you’ve written.
    Just my opinion, it could bring your posts a
    little bit more interesting.

  3. Heya! I know this is kind of off-topic however I needed to ask.
    Does operating a well-established blog such as yours take a large amount of work?
    I’m completely new to writing a blog but I do write in my diary every day. I’d like to start a blog so I can easily
    share my experience and views online. Please
    let me know if you have any ideas or tips for brand
    new aspiring blog owners. Appreciate it!

  4. karen millen dress
    karen millen dress June 19, 2013

    For example, a complete 3-5 kilowatt gadget might cost $200 Euros and latest 20-30 years.
    Further items include jewelry, belts, shoes so coats.
    Hertz is the unit in which persistence is measured. The love
    of using dress up, became as she performed. karen millen dress.

  5. 龙安
    龙安 September 11, 2012

    下载链接已经失败了,压缩包错误,另外官方的也下不了了,更新下地址吧

  6. […] buffer_explorer:be 出已在buffer的文件列表 phpmanual来自鸟哥博客http://www.laruence.com/2010/08/18/1718.html 有参照http://nootn.com/blog/Tool/22/ 其它东拼西凑了些,都瞎找的,不知道哪了 […]

  7. […] 今天在http://www.laruence.com/2010/08/18/1718.html看到将PHP_Manual整合到Gvim,就照着做了一遍,可是按K键,gvim提示:E149:抱歉,没有 ***** 的说明。重新检查一遍,都没有错呀,用:set runtimepath<CR>查看,manual的路径也在runtimepath里面了,但就是不行,又找不到原因。根据http://edt1023.sayya.org/vim/node13.html里面的说明: […]

  8. 何林丹
    何林丹 December 2, 2011

    操作把phpmanual目录添加到runtimepath
    set runtimepath +=d:/phpmanual
    需注意几点:
    1.=与路径之间不能有空格
    2.window下时路径中不能有空格。
    3.路径不能加双引号
    4.多个路径需要逗号(半角)隔开

  9. Anonymous
    Anonymous November 28, 2011

    楼主,我按照你说的做了,可以就是找不到,提示的错误是
    E149: Sorry, no help for dirname
    不知道是为什么,烦请解答

  10. liuzhiqiang
    liuzhiqiang June 6, 2011

    恩,这样确实很方便,以后就不用去manual了。尤其上不去网的时候,最揪心。

  11. liruqi
    liruqi December 24, 2010

    配置成功,thanks~~~

  12. moncler
    moncler December 1, 2010

    then run :helptags [path to vim/doc]. Documentation for PHP functions can be shown by pressing K while the cursor is on a function name.

  13. pangyongtao
    pangyongtao November 30, 2010

    Download http://planetxml.de/php_manual.txt and put it into your vim/doc folder, then run :helptags [path to vim/doc]. Documentation for PHP functions can be shown by pressing K while the cursor is on a function name.
    虽然版本旧, 不过部署方法简单, 呵呵

  14. 雪候鸟
    雪候鸟 September 28, 2010

    @wl 已经添加, 私聊

  15. wl
    wl September 28, 2010

    真心求教
    看了你的这些文章,感觉不是很系统,有些看不明白。
    能不能给点指点?
    我想把smarty写成扩展模块。
    刚刚做了个demo,实现了简单的变量替换。
    希望能得到你的帮助,我找不到你的IM联系方式,请加我QQ, 24327475 谢谢

  16. 技术网
    技术网 August 30, 2010

    还没试用,先谢谢分享

  17. air max shoes
    air max shoes August 25, 2010

    是挺慢的 不过很好用哦!

  18. nfl football jerseys
    nfl football jerseys August 23, 2010

    博主绝对是VIM高手,提供的很详细,刚试了一下,很好用,谢谢了

  19. 谷哥QQ
    谷哥QQ August 22, 2010

    感谢分享!

  20. 张二
    张二 August 21, 2010

    呵呵,试了一下,果然V5,比较懒,set runtimepath发现.vim/doc已经包含在runtimepath变量中了,由于直接cd ~/.vim,然后解压了鸟哥的包(好多文件),然后设置了一下.vimrc……很好用哦。

  21. simplechen
    simplechen August 18, 2010

    兄弟你是用VIM的老手了,能否分享一下你的VIM配置。:) 多谢!

  22. 雪候鸟
    雪候鸟 August 18, 2010

    @felix021 :help和”help”(有引号)都可, 🙂

  23. felix021
    felix021 August 18, 2010

    感谢分享!
    .tar.gz下载有点儿慢。
    另外,keywordprg应该是 :help
    autocmd FileType php set keywordprg=:help

  24. xiaokai
    xiaokai August 18, 2010

    下班回家试试..

Comments are closed.