English 中文(简体)
VIM 自动加入
原标题:VIM Insert PHPdoc automatically
  • 时间:2011-09-29 21:12:54
  •  标签:
  • vim
  • phpdoc

使用指挥或关键组合在VIM插入PHPDoc的方法吗?

例如,我有一个班子:

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
*/

那么,我可以人工地完成其余部分。 谢谢。

最佳回答

可与轻度phpDocumentor plugin有效。

http://www.vim.org/scripts/script.php?script_id=2980“rel=“noreferer” 这里有经过修改的版,最近有所发展。

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

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> 

以上规定,在插入、正常和直观模式中,“www.un.org/french/ga/president 将你的 cur放在一个类别、功能或可变的定义上,新闻Ctrlp,而原始材料将试图根据定义形成一个 do块。

Example function doc block:

/**
 * 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 {

}

Full abstract class example:

<?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...
  }
}
?>
问题回答

Assume you place your template at ~/templates/phpdoc.php. With the below abbreviation, if you type ,p, you will read the contents of your phpdoc.php into the current file, ( at or below the current line - one of those ).

map ,p :r ~/templates/phpdoc.php<cr>

Then just add the line to your .vimrc file, replacing the file-path and ,p to your liking.

I can t speak for PHP specifically but you have a couple of options. You can use abbreviations (maybe not good for the specific example) or you can look for a plugin. I can suggest https://github.com/garbas/vim-snipmate ( I use it and it works fine).





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签