VIM 自动插入 PHPdoc [英] VIM Insert PHPdoc automatically

查看:19
本文介绍了VIM 自动插入 PHPdoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用命令或组合键在 VIM 中插入 PHPDoc?

Is there a way to insert PHPDoc in VIM using a command or key combination?

例如,我有一个类:

class MyClass
{

  public function __construct() { }
  public function __destruct() { }

  /* command here to insert PHP doc */
  public function abc() { }

}

我想插入如下内容:

/**
* method() 
*
* description
*
* @access   
* @author    
* @param    type    $varname    description
* @return   type    description
* @copyright
* @version
*/

然后我可以手动填写其余部分.谢谢

And then I can full out the rest manually. Thank you

推荐答案

这可以通过轻量级的 phpDocumentor 插件.

This can be done pretty effectively with the lightweight phpDocumentor plugin.

编辑 这是修改后的版本随着最近的发展.

编辑 这是 phpDocumentor 插件的第 2 版.比上面两个链接更新.

Edit Here's version 2 of the phpDocumentor plugin. It is more recent than the above two links.

将插件安装到您的 $VIMFILES/plugin 目录并将其添加到您的 .vimrc 中:

Install the plugin into your $VIMFILES/plugin directory and add this to your .vimrc:

" PHP documenter script bound to Control-P
autocmd FileType php inoremap <C-p> <ESC>:call PhpDocSingle()<CR>i
autocmd FileType php nnoremap <C-p> :call PhpDocSingle()<CR>
autocmd FileType php vnoremap <C-p> :call PhpDocRange()<CR> 

以上在插入、正常和可视模式下将 phpDocumentor 绑定到 Ctrlp.将光标放在类、函数或变量定义上,按 Ctrlp,插件将尝试根据定义形成一个文档块.

The above binds phpDocumentor to Ctrlp in insert, normal, and visual modes. Place your cursor on a class, function, or variable definition, press Ctrlp, and the plugin will attempt to form a doc block based on the definition.

/**
 * testDocBlock 
 * 
 * @param mixed $param1 
 * @param mixed $param2 
 * @static
 * @access public
 * @return boolean
 */
public static function testDocBlock($param1, $param2) {
  // Pressed Ctl-p while cursor was on the function definition line above...
}

示例类文档块

版权、版本、作者等默认包含在类文档块中.您可以修改插件以包含您自己的默认值:

Example class doc block

Copyright, version, author, etc are included by default in a class doc block. You can modify the plugin to include your own default values for these:

/**
 * TestClass  
 * 
 * @package 
 * @version $id$
 * @copyright 
 * @author Michael <me@exmaple.com> 
 * @license 
 */
class TestClass {

}

完整抽象类示例:

<?php
/**
 * TestClass 
 * 
 * @abstract
 * @package 
 * @version $id$
 * @copyright 
 * @author Michael <email@example.com>
 * @license 
 */
abstract class TestClass {
  /**
   * publicProp  
   * 
   * @var string
   * @access public
   */
  public $publicProp;
  /**
   * privateProp  
   * 
   * @var string
   * @access private
   */
  private $privateProp;

  /**
   * testDocBlock  
   * 
   * @param string $param1 
   * @param string $param2 
   * @static
   * @access public
   * @return boolean
   */
  public static function testDocBlock($param1, $param2) {
    // code here...
  }
}
?>

这篇关于VIM 自动插入 PHPdoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆