Vim PHP omni completion

前端 未结 9 1014
醉话见心
醉话见心 2020-12-07 12:44

I\'m trying to get PHP autocompletion right in Vim. Right now when I do a $blog = new Blog(); $blog-> and then hit CTRL+X CTRL+O I\'d expect omn

9条回答
  •  無奈伤痛
    2020-12-07 12:55

    Omnicompletion will only work if the tag file contains both the class definition, and the variable declaration.

    Straightforward solution

    In general that means that you will need to save and (re)generate the tags file after the class Blog { ... } and $blog = new Blog(); parts, but before trying $blog-> . This is because the PHP omni-complete function will look for the class declaration of the $blog variable in the tags file.

    (BTW if you have opened the tags file in a buffer, reload it after regenerating it.)

    Alternative

    The vim documentation (:help ft-php-omni) also defines a way which doesn't require the variable to be indexed in the tags file, but uses instead a specific comment on the preceding line:

    /* @var $myVar myClass */
    $myVar->
    

    However, the class definition still does need to be in the tag file, and the comment is needed every time you want to use omni-complete. So typing away in a new PHP file still won't give you nice omni-completion :(

    Just a thought

    Maybe it is possible to generate on-the-fly a temporary tags file (like the taglist plugin) of just the unsaved buffer, and allow omni-complete to use it too?? I'm not a great vim hacker though...

提交回复
热议问题