If I am coding in PHP and I type out a PHP built-in function (e.g. explode()) vims standard omni-complete would normally provide a function signature in a preview window.
I recently installed a couple of plugins and now the function signature preview doesnt seem to work, is there any way to manually invoke this preview window with function signature?


In theory you could go to the end of the function and and press <c-x><c-o> if 'completeopt' has menuone set. However this will add an extra paren at the end of the function.

I use the following snippet in my ~/.vim/after/ftplugin/php.vim file:

function! s:PHPQuickMan(word)
  if !exists('g:php_builtin_functions')
    call phpcomplete#LoadData()
  let word = a:word . '('
  if !get(b:, 'php_quick_man_color', get(g:, 'php_quick_man_color', 1))
    echo word . get(g:php_builtin_functions, word, ' can not be found')
    let sig = get(g:php_builtin_functions, word, '')
    if sig == ''
      echohl WarningMsg
      echo word . ' can not be found'
      echohl None
      echon word
      for part in split(matchstr(sig, '.*\ze|\s\+\w\+$'), '\<')
        echohl Directory
        let w = matchstr(part, '\v^(int|array|mixed|callable|object|string|bool|void|resource)')
        echon w
        echohl None
        echon strpart(part, len(w))
      echon ") | "
      echohl WarningMsg
      echon matchstr(sig, '|\s\+\zs\w\+$')
      echohl None

nnoremap <buffer> K :call <SID>PHPQuickMan(expand('<cword>'))<cr>

This leverages the php's omni-complete database to print out at the bottom of the screen the function signature when you press K on a function.

For more help see:

:h 'completeopt'
:h compl-omni
:h K
:h 'keywordprg'
  • awesome, thanks for this! I can get it to work for straight functions, but not for methods, e.g. it doesnt work on $dbh->prepare($sql) whereas vims builtin omni complete does provide assistance for prepare() - when its called on an object (but wont if its not used in an object context) – the_velour_fog Oct 8 '15 at 19:05
  • I should have been more clear it uses Vim builtin omni complete for functions via g:php_builtin_functions. – Peter Rincker Oct 8 '15 at 19:59
  • thats the weird thing, vim's builtin onmi-complete - for methods - does work, but when I invoke the method signature with your snippet it doesnt work. just to repeat: you snippet works fine on builtin functions - its just methods that dont seem to work – the_velour_fog Oct 9 '15 at 2:35
  • Since the snippet uses g:php_builtin_functions it has no support for methods, just functions. Please feel free to improve upon it to work for methods calls – Peter Rincker Oct 9 '15 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.