FormatComment.vim


Ⅰ. 插件描述

Format-block (do a 'gq' format) on the comment the cursor is in

Ⅱ. 基本信息

创建日期:  2004-01-28
使用用户:  1
Github星:  1
插件作者:  Gary Holloway

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/formatcomment-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/formatcomment-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/formatcomment-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/FormatComment.vim

Ⅳ. 文档说明

" Format-block (do a 'gq' format) on the comment the cursor is in; the type of
" comment is determined by context (i.e., /.../, //..., #..., etc.).
"
" EXAMPLE SETUP
" map gqc :call FormatComment()<CR>

DEPENDENCIES:
   FormatBlock.vim ( vimscript #885 )

My actual setup is:

" gqc - Format comment; comment-type is determined by context (i.e., /.../,
"       //..., #..., etc.).
"
" NOTE: This will probably not work properly in C source for vim versions prior
"       to 6 because some of the search-patterns used are more advanced than
"       were available prior to version 6.
exe SILENT . 'map <unique> gqc :call FormatComment()<CR>'

Where SILENT is set to '' or 'silent! ', depending upon vim's version (does it have silent?)

There is some stuff in there to handle our organization's "standard function header" comments specially; that 'if' block should be easily located and removed, or modified to your tastes.  If left as-is, you probably wouldn't trigger it anyway (so I left it in there as an example/template).

Also, we use the convention that single-line 'C' comments should use the //-style, while multi-line comments should use the /.../-style; so that's built into the function.  i.e., If a long //-style comment gets formatted onto multiple lines, it will be converted to /.../-style; while a /.../-style comment that fits onto a single line will be converted to //-style.  If this is not to your liking, it should be easily remedied; there are function calls made to to the conversions, simply comment the call(s) out (or remove them).

This function allows quick entry/editing of comments without worrying about the line-break formatting.  Once finished, simply hit 'gqc' and the comment is reformatted.

添加新评论