Ⅰ. 插件描述
C++ Code auto-gen utility for VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'horosphere/formatgen'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'horosphere/formatgen'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'horosphere/formatgen'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/horosphere/formatgen
Ⅳ. 文档说明
# formatGen
C++ Code auto-gen utility. Currently can be used to generate include guards and
namespaces.
Installation
You can use any vim plugin manager ([Pathogen](
https://github.com/tpope/vim-pathogen),
Vundle, etc.) to manage formatGen.
Usage
To use formatGen on any C++ project, create a file named .formatGen
in a
parent directory of all source files. The .formatGen
file should contain the
following:
<format>
<src-folder>
The first line <format>
is the style of the include guards. The following
tokens will be replaced:
{DIR}, {Dir}, {dir}
-> upper, normal, lower case directory name, separated- underscores
{FNAME}, {FName}, {fname}
-> upper, normal, lower case file name. The file- must not contain dots.
{EXT}, {Ext}, {ext}
-> file extension.
The second line is the common parent directory to all headers. For example, if
your project is structured like this:
.formatGen
LICENSE
README.md
--/src <- Here lies all of your headers
--...
--/bin
--...
Then <src-folder>
should be src
, with no slashes.
Example:
_CPPTEST_{DIR}_{FName}_{ext}__
src
When formatGen's include guard generator is applied to the filesrc/core/Server.hpp
, it generates the following include guard:
#ifndef _CPPTEST_CORE_Server_hpp__
#define _CPPTEST_CORE_Server_hpp__
#endif // !_CPPTEST_CORE_Server_hpp__
Include guard generation
Executing the script cppFormatHeaderGuard.py
formats either all headers or a
list of headers specified in the argument. The present working directory must
be a daughter directory of where .formatGen
resides.
You can also run this script within Vim using :FGIncludeGuard <path>
, where<path>
is the path to your file. It is needed since there is no way to query
the file path using Vim.
Rules
formatGen automatically detects existing include guards. If none exists, it
will create its own. The include guard must qualify the following conditions to
be detected correctly.
- Include guards do not have preceding white spaces.
#define
and#ifndef
must be on adjacent lines.- If there are preprocessor commands that look like an include guard, they
- be identified as an include guard and problems can occur. This will be
fixed in the future.
Namespace generation
Using the vim command :FGNamespace name
generates
namespace name
{
} // namespace name
On top of the cursor.
Utilities
The utilities do not require a .formatGen
configuration file.
updateCMake.py
automatically fetches a list of C++ source files from the
specified directory and add them automatically to the CMakeLists.txt
in thepwd
. updateCMakeQt.py
has additional Qt MOC support. See the scripts for
details.