日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ubuntu新建python代码文件_[Vim]新建python文件自动添加python header

發(fā)布時間:2025/10/17 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu新建python代码文件_[Vim]新建python文件自动添加python header 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用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的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。