1. 安装SublimeTmpl插件
通过package control 安装 或 Git clone https://github.com/kairyou/SublimeTmpl到/Sublime Text 3/Packages文件夹下
2. 自定义模板
进入 /Sublime Text 3/Packages\User\SublimeTmpl\templates目录下创建自己的模版(可参考/Sublime Text 3/Packages/SublimeTmpl/templates 下的模版)
c.tmpl
/******************************************************************************
*
* Filename: ${saved_filename}
*
* Description: $0
*
* %date_created: ${date} %
* %version: 1 %
* %authors: ${author} (${email}) %
*
* Copyright 2017-, ${company}
* All rights reserved.
*****************************************************************************/
/******************************************************************************
* Include Files
*****************************************************************************/
/******************************************************************************
* Macro Definitions
*****************************************************************************/
/******************************************************************************
* Const Definitions
*****************************************************************************/
/*****************************************************************************
* Global Variables Definitions
*****************************************************************************/
/*****************************************************************************
* Local Function declarations
*****************************************************************************/
/*****************************************************************************
* Function Definitions
*****************************************************************************/
/******************************************************************************
*
* Revision History:
*
* Rev. YYMMDD Who Changes
* 1 ${date} ${author} New Created.
******************************************************************************/
h.tmpl
#ifndef ${saved_filenameWithoutExt}_H
#define ${saved_filenameWithoutExt}_H
/******************************************************************************
*
* Filename: ${saved_filename}
*
* Description: $0
*
* %date_created: ${date} %
* %version: 1 %
* %authors: ${author} (${email}) %
*
* Copyright 2017-, ${company}
* All rights reserved.
*****************************************************************************/
/******************************************************************************
* Include Files
*****************************************************************************/
/******************************************************************************
* Macro Definitions
*****************************************************************************/
/******************************************************************************
* Const Definitions
*****************************************************************************/
/*****************************************************************************
* Type Definitions
*****************************************************************************/
/*****************************************************************************
* Extern Variables
*****************************************************************************/
/*****************************************************************************
* Function Prototypes
*****************************************************************************/
#endif /*${saved_filenameWithoutExt}_H*/
/******************************************************************************
*
* Revision History:
*
* Rev. YYMMDD Who Changes
* 1 ${date} ${author} New Created.
******************************************************************************/
3. 自定义配置
配置Sublime Text / Preferences / Package Settings / SublimeTmpl / Setting-user (可参考 Setting-Default 的配置)
- 新增C语言支持:
"source": {
"syntax": "Packages/C/C.tmLanguage",
"extension": "c"
},
"header": {
"syntax": "Packages/C/H.tmLanguage",
"extension": "h"
},
- 快捷键, 支持文件名,文件路径及工程路径配置
"disable_keymap_actions": false, // "all"; "html,css"
"enable_project_variables": true, // ${project_base_name}, ${project_path} and ${platform}
"enable_file_variables_on_save": true, // ${saved_filename}, ${saved_filepath} on save file
- 支持避免重复包含头文件的宏大写
#ifndef ${saved_filenameWithoutExt}_H
#define ${saved_filenameWithoutExt}_H
[文件体]
#endif
在sublime-tmpl.py中添加如下代码
FileNameWithoutExtension = os.path.splitext(filename)[0]
FileNameWithoutExtension = FileNameWithoutExtension.upper()
view.run_command('sublime_tmpl_replace', {'old': '${saved_filenameWithoutExt}', 'new': FileNameWithoutExtension})
- 支持自定义属性
"attr": {
"author": "your name" ,
"email": "mail@yours.com",
"link": "http://yours.com"
}
- 新增开始菜单: 可以在SublimeTmpl / Settings - Menu里, 参照其他语法增加c和h.
{
"id": "c",
"caption": "c",
"command": "sublime_tmpl",
"args": {
"type": "c"
}
},
- 新增快捷键:在SublimeTmpl / Key Bindings User中添加
{
"keys": ["ctrl+alt+c"], "command": "sublime_tmpl",
"args": {"type": "c"}, "context": [{"key": "sublime_tmpl.c"}]
},
Enjoy it!