ubuntu新建python代码文件_[Vim]新建python文件自动添加python header
使用vim腳本來實現(xiàn)的,使用了模板,幾行代碼就能實現(xiàn)很實用。
~/.vimrc 中的代碼
"auto add pyhton header --start
autocmd BufNewFile *.py 0r ~/.vim/vim_template/vim_pyhton_header
autocmd BufNewFile *.py ks|call FileName()|'s
autocmd BufNewFile *.py ks|call CreatedTime()|'s
fun FileName()
if line("$") > 10
let l = 10 "這里是字母L 不是數(shù)字1
else
let l = line("$")
endif
exe "1," . l . "g/File Name:.*/s/File Name:.*/File Name: " .expand("%")
"最前面是數(shù)字1,這里的File Name: 要和模板中一致
endfun
fun CreatedTime()
if line("$") > 10
let l = 10
else
let 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.py
lzz@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
############################
其他語言也可以類似的編程,這樣就不用每次都在代碼開頭寫各種頭文件啊,協(xié)議啊,作者,日期啥的了。
總結
以上是生活随笔為你收集整理的ubuntu新建python代码文件_[Vim]新建python文件自动添加python header的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java arraylist排序_Jav
- 下一篇: influxdb java_身为Java