详解pycharm新建文件时头部的模板
2017-05-04 22:12
519 查看
原文地址:点击打开链接
pycharm新建文件时的头部模板,即默认的:author = ‘$USER’,pycharm下依次“File→settings→Editor→File and Code Template”即可找到界面,如下:
JetBrains的官方帮助文档里说的很详细了,这里画蛇添足赘述一下,努力做到详细精确,傻瓜操作,即copy即用:
pycharm总共支持四种方法来创建模板:
1. Creating a file template from scratch
2. Creating a file template from an existing one
3. Creating a file template from a file
4. Creating and referencing include templates
这是最简单常用的一种方法,以Python为例,模板的默认头部为:
2
1
2
其他的一些可选的预定义变量有:
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
例如,如果你还想加上该文件创建的时间:
1
当然,也可以组合使用:
2
3
4
5
1
2
3
4
5
而如果你觉得预定义的这些太少啦,不能满足你狂拽酷炫的需求,那么,pycharm也支持自定义,格式为:
2
3
4
5
1
2
3
4
5
还可以覆盖预定义变量:
2
3
4
5
1
2
3
4
5
美元符号本身用’${DS}’,示例:
2
3
4
1
2
3
4
就是copy已存在的头文件模板,示意图如下:
先选中一个要copy的模板,然后点击复制,效果如下:
这个是将一个文件保存为模板,示意图如下:
这时再次按照“File→settings→Editor→File and Code Template”打开,就会发现刚刚添加的模板了。
这里用到了Template选项旁边的include选项:
点击“+”号创建,写入内容,然后再返回Template选项通过“parse”来引用,这里依然以python的模板为例:
显示如下:
pycharm新建文件时的头部模板,即默认的:author = ‘$USER’,pycharm下依次“File→settings→Editor→File and Code Template”即可找到界面,如下:
如何对pycharm头部模板进行个人的全新定制呢?
JetBrains的官方帮助文档里说的很详细了,这里画蛇添足赘述一下,努力做到详细精确,傻瓜操作,即copy即用:pycharm总共支持四种方法来创建模板:
1. Creating a file template from scratch
2. Creating a file template from an existing one
3. Creating a file template from a file
4. Creating and referencing include templates
1、Creating a file template from scratch
这是最简单常用的一种方法,以Python为例,模板的默认头部为:__author__ = '$USER' # '$USER' 为预定义的变量,为你当前登录的计算机用户名1
2
1
2
其他的一些可选的预定义变量有:
${PROJECT_NAME} - the name of the current project. ${NAME} - the name of the new file which you specify in the New File dialog box during the file creation. ${USER} - the login name of the current user. ${DATE} - the current system date. ${TIME} - the current system time. ${YEAR} - the current year. ${MONTH} - the current month. ${DAY} - the current day of the month. ${HOUR} - the current hour. ${MINUTE} - the current minute. ${PRODUCT_NAME} - the name of the IDE in which the file will be created. ${MONTH_NAME_SHORT} - the first 3 letters of the month name. Example: Jan, Feb, etc. ${MONTH_NAME_FULL} - full name of a month. Example: January, February, etc.1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
例如,如果你还想加上该文件创建的时间:
__time__ = '${DATE}'1
1
当然,也可以组合使用:
__time__ = '${DATE} ${TIME}' #显示如下: __author__ = 'oukohou' __time__ = '2017/3/14 10:46'1
2
3
4
5
1
2
3
4
5
而如果你觉得预定义的这些太少啦,不能满足你狂拽酷炫的需求,那么,pycharm也支持自定义,格式为:
#set( $GirlFriend = "Jingjing" ) __girlFriend__ = '${GirlFriend}' 显示如下: __girlFriend__ = 'Jingjing'1
2
3
4
5
1
2
3
4
5
还可以覆盖预定义变量:
#set($USER = "Handsome") __author__ = '$USER' #显示如下: __author__ = 'Handsome'1
2
3
4
5
1
2
3
4
5
美元符号本身用’${DS}’,示例:
__dollar__ = '${DS}' #显示如下: __dollar__ = '$'1
2
3
4
1
2
3
4
2、Creating a file template from an existing one
就是copy已存在的头文件模板,示意图如下: 先选中一个要copy的模板,然后点击复制,效果如下:
3、Creating a file template from a file
这个是将一个文件保存为模板,示意图如下:这时再次按照“File→settings→Editor→File and Code Template”打开,就会发现刚刚添加的模板了。
4、Creating and referencing include templates
这里用到了Template选项旁边的include选项:点击“+”号创建,写入内容,然后再返回Template选项通过“parse”来引用,这里依然以python的模板为例:
显示如下:
# -*- coding: utf-8 -*- __author__ = 'Handsome' __time__ = '2017/3/14 14:28' __girlFriend__ = 'Jingjing' __dollar__ = '$' hello, Jingjing. # If this runs wrong, don't ask me, I don't know why; # If this runs right, thank god, and I don't know why. # Maybe the answer, my friend, is blowing in the wind.
相关文章推荐
- 详解pycharm新建文件时头部的模板
- 详解pycharm新建文件时头部的模板
- pycharm 修改新建文件时的头部模板
- PyCharm 修改新建文件时的头部模板
- pycharm 修改新建文件的头部模板
- pycharm 修改新建文件时的头部模板(默认为__author__='...')
- PyCharm设置python新建文件 模板修改 设置 文件为python 和utf-8 解决控制台输出乱码
- PyCharm 设置Python 文件头部模板
- 【转】Pycharm创建py文件时自定义头部模板
- django 在pycharm 中添加模板省去每次新建py文件都要写一样的开头
- netBeans 修改新建php文件头部注释模板
- Pycharm创建py文件时自定义头部模板
- Spring 配置文件XML头部文件模板实例详解
- Pycharm创建py文件时自定义头部模板
- VS2008中自定义C++工程模板与修改新建文件默认编码的办法
- VS中如何自定义新建文件模板(添加自定义版权信息)
- Dx模板代码解析--header(头部文件)
- VS2012自定义新建文件模板方法
- (转)xcode 4.2 新建工程模板详解
- xcode_4.2_新建工程模板详解