Pycharm自定义文件和代码模板

by LauCyun Nov 21,2016 21:02:11 20,836 views

PyCharm提供了文件和代码模板功能,可以利用此模板来快捷新建代码或文件。IDE默认的是空白文件,但是我们希望增加个性化的内容,比如在PyCharm中新建一个py文件,会自动填充如下内容:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
 Name        : laucyun.py
 Created on  : 2016/11/21 21:00
 Author      : LauCyun<liu@liuker.xyz>
 Version     : 1.0.0
 Copyright   : Copyright (C) 2016 - 2017, LauCyun, https://laucyun.com.
 Description : .
"""

首先进入File -> Setting -> Editor -> File and Code Templates(如图1所示),添加以下内容:

图1 Python's File and Code Templates

Python:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
    ${NAME}
    ~~~~ on ${MONTH_NAME_FULL} ${DAY},${YEAR} ${HOUR}:${MINUTE}
    
    The description is written here.
    
    :license MIT, see LICENSE for more details.
#if ($YEAR == "2013")
    :copyright (c) 2013 by laucyun<liu@liuker.xyz>.
#else
    :copyright (c) 2013 - $YEAR by LauCyun<liu@liuker.xyz>.
#end
"""

C/C++:

/*
* ${FILE_NAME}
* ~~~~ on ${MONTH_NAME_FULL} ${DAY},${YEAR} ${HOUR}:${MINUTE}
*
* The description is written here.
*
* :license MIT, see LICENSE for more details.
#if ($YEAR == "2013")
* :copyright (C) 2013 by LauCyun<liu@liuker.xyz>.
#else
* :copyright (C) 2013 - $YEAR by LauCyun<liu@liuker.xyz>.
#end
*/

Lua:

--
-- ${FILE_NAME}
-- ~~~~ on ${MONTH_NAME_FULL} ${DAY},${YEAR} ${HOUR}:${MINUTE}
-- 
-- The description is written here.
--
#if ($YEAR == "2013")
-- Copyright: Copyright (C) 2013 by LauCyun<liu@liuker.xyz>.
#else
-- Copyright: Copyright (C) 2013 - $YEAR by LauCyun<liu@liuker.xyz>.
#end
--

JavaScript:

/**
 * ${FILE_NAME}
 * ~~~~ on ${MONTH_NAME_FULL} ${DAY},${YEAR} ${HOUR}:${MINUTE}
 * 
 * The description is written here.
 * 
#if ($YEAR == "2013")
 * Copyright   : Copyright (C) 2013 by LauCyun<liu@liuker.xyz>.
#else
 * Copyright   : Copyright (C) 2013 - $YEAR by LauCyun<liu@liuker.xyz>.
#end
 */

 

具体的参数设置,请参考官方文档File and Code Templates

Tags