[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