[Vim] New Python file automatically add Python header

Source: Internet
Author: User
Tags tag name

using a VIM script, using a template, a few lines of code can be implemented very useful.
code in the ~/.VIMRC
"Auto Add Pyhton header--startautocmd bufnewfile *.py 0r ~/.vim/vim_template/vim_pyhton_headerautocmd BufNewFile *.py ks |call FileName () | ' Sautocmd bufnewfile *.py ks|call createdtime () | ' Sfun FileName () If line ("$") > 10let L = Ten  "Here is the letter L is not the number 1 elselet l = line (" $ ") endif EXE" 1, ". "G/file name:.*/s/file name:.*/file Name:". Expand ("%")         "The first is the number 1, here's the File Name: to be consistent with the template Endfun Fun createdtime () if Line ("$") > 10let L = 10elselet L = line ("$") endif EXE "1,". L. "G/created time:.*/s/created time:.*/created Time:". Strftime ("%y-%m-%d%T")         "Create time here: to be consistent with the template Endfun" auto Add Python header--end

The template code file is~/.vim/vim_template/vim_pyhton_header
#!/usr/bin/python#-*-coding:utf-8-*-############################ #File Name: #Author: orangleliu#mail: [Email Protected] #Created time:############################

Description 1 template paths to be consistent2 Don't forget to keep. VIMRC in the Replace tag name and template in the same example Create time:
Test results
[Email protected]:~$ vim c.py[email protected]:~$ cat c.py #!/usr/bin/python#-*-coding:utf-8-*-###################### ###### #File name:c.py#author:orangleliu#mail: [email protected] #Created time:2014-12-11 20:16:33################### #########

Other languages can also be programmed similarly, so that you don't have to write all kinds of header files at the beginning of the code, the Protocol, the author, and the date.

Reference: https://gist.github.com/zxkletters/6521114

This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41902851

Author Orangleliu using Attribution-NonCommercial-sharing protocol in the same way

[Vim] New Python file automatically add Python header

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.