[Vim]建立python檔案自動添加python header,
使用vim指令碼來實現的,使用了模板,幾行代碼就能實現很實用。
~/.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 "這裡是字母L 不是數字1 elselet l = line("$")endif exe "1," . l . "g/File Name:.*/s/File Name:.*/File Name: " .expand("%") "最前面是數字1,這裡的File Name: 要和模板中一致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: 要和模板中一致endfun "auto add python header --end
模板代碼 檔案為~/.vim/vim_template/vim_pyhton_header
#!/usr/bin/python#-*- coding:utf-8 -*-#############################File Name:#Author: orangleliu#Mail: orangleliu@gmail.com#Created Time:############################
說明1 模板路徑要一致2 不要忘了保持 .vimrc中替換標籤名稱和模板中一致 例如 Create Time:
測試結果
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############################
其他語言也可以類似的編程,這樣就不用每次都在代碼開頭寫各種標頭檔啊,協議啊,作者,日期啥的了。
參考:https://gist.github.com/zxkletters/6521114
本文出自 “orangleliu筆記本” 部落格,轉載請務必保留此出處http://blog.csdn.net/orangleliu/article/details/41902851
作者orangleliu 採用署名-非商業性使用-相同方式共用協議