我用Vundle安装了phpcomplete.vim,希望我能为PHP自动完成。
但是,只出现了几个 mysqli 函数。甚至mysqli_connect()都没有出现。
我做错了什么或这些功能没有实现吗?我可以用其他插件或其他东西获得它们吗?
编辑:这篇文章讨论了 Vim 7.4 附带的 phpcomplete.vim 版本。有问题的版本是shawncplus的版本:phpcomplete.vim。我强烈建议升级以使用shawncplus版本,因为它更完整(双关语!
旧 phpcomplete.vim
可悲的是,php 完整地表示 Vim 附带的没有很多通用功能,例如 json_decode
.我自己添加了完成条目。
将以下内容添加到~/.vim/after/ftplugin/php.vim
:
if !exists('g:php_builtin_functions')
call phpcomplete#LoadData()
let g:php_builtin_functions['json_decode('] = 'string $json [, bool $assoc [, int $depth [, int $options]]] | mixed'
let g:php_builtin_functions['json_encode('] = 'mixed $value [, int $options [, int $depth]] | string'
let g:php_builtin_functions['json_last_error_msg('] = 'void | string'
let g:php_builtin_functions['json_last_error('] = 'void | int'
endif
注意:我的示例只是添加了 JSON 函数。您需要为 mysqli 函数更改这些内容。
作为奖励,这是我用于 php 文件的 K
命令版本(放入 ~/.vim/after/ftplugin/php.vim
):
function! s:PHPQuickMan(word)
let word = a:word . '('
echo word . get(g:php_builtin_functions, word, ' can not be found')
endfunction
nnoremap <buffer> K :call <SID>PHPQuickMan(expand('<cword>'))<cr>
问题似乎是内置函数/类映射(注意,这是一个相当大的文件)不包含每个mysqli_*
函数,就像mysql_connect
一样(有些函数像mysqli_get_cache_stats
一样)。
根本原因可能是由于从文档中生成这些映射的代码,在这种情况下,这可能是一个错误/缺乏对这些类型的别名(如mysqli_connect
)和函数的支持,这些函数既可以调用过程,也可以通过各种mysqli相关类(如mysqli_close
)。
如果您使用的是插件的 github 主版本,您可以通过 misc/builtin_manual.vim
文件手动添加条目,它看起来像这样(只需将其添加到文件末尾):
call extend(g:phpcomplete_builtin['functions']['mysqli'], {
'mysqli_connect(': '[ string $host = ini_get("mysqli.default_host") [, string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] | mysqli',
'mysqli_escape_string(': 'string $escapestr | string',
'mysqli_execute(': ' mysqli_stmt $stmt | bool',
'mysqli_set_opt(': ' mysqli $link, int $option, mixed $value | bool',
})
只需添加更多您希望在结果中看到的内容即可。
如果你想使用内置地图(当我写这篇文章时,它们已经 10 个月没有更新了),你可以在这里找到生成器,你需要来自 php.net 和命令行 php 的文档。
如果您能在 github 上提出一个问题,我将不胜感激,这样我们就可以有一个合适的地方进行讨论等等。
更新:
我已经推送了一个带有更新的内置映射并支持生成器中"过程样式"别名的提交。