[Vim] automatically add a python header to a new python file,

Source: Internet
Author: User

[Vim] automatically add a python header to a new python file,
Use the vim script to implement it. With the template, several lines of code can be very practical.
~ /. Code in 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 = 10 "Here is the letter L not number 1 elselet l = line (" $ ") endif exe" 1 ,". l. "g/File Name :. */s/File Name :. */File Name :". expand ("%") "is preceded by a number 1. The File Name here must be consistent with the endfun fun CreatedTime () if line (" $ ")> 10let l = 10 elselet l = line ("$") endif exe "1 ,". l. "g/Created Time :. */s/Created Time :. */Created Time :". strftime ("% Y-% m-% d % T") "Create Time here: 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: orangleliu@gmail.com#Created Time:############################

NOTE 1: The template path should be consistent. 2 do not forget to keep the. vimrc Replace the tag name with the same in the template. For example, Create Time:
Test Results
lzz@ubuntu:~$ vim c.pylzz@ubuntu:~$ cat c.py #!/usr/bin/python#-*- coding:utf-8 -*-#############################File Name: c.py#Author: orangleliu#Mail: orangleliu@gmail.com#Created Time: 2014-12-11 20:16:33############################

Other languages can also adopt similar programming, so that you don't need to write various header files at the beginning of the code every time. What are the protocols, authors, and dates.

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

This article from the "orangleliu notebook" blog, reprint please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41902851

Author orangleliu adopts signature-non-commercial use-share protocol in the same way

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.