vim 上有自动更新编辑时间,新建文件自动头部添加自定义注释信息的插件吗

2014-12-14 21:15:53 +08:00
 zeroday
5485 次点击
所在节点    问与答
4 条回复
jiang42
2014-12-14 21:46:06 +08:00
同求,现在是用UltiSnips 添加,也还行
jamesxu
2014-12-14 21:58:33 +08:00
1、http://www.vim.org/scripts/script.php?script_id=4786
2、参考:au BufNewFile *.py 0r ~/.vim/skeletons/skel.python
weegc
2014-12-15 10:06:21 +08:00
试试snipmate
josephpei
2014-12-15 10:15:14 +08:00
function ReadTempl(fname)
let l:fpath=expand(a:fname)
let l:lines=readfile(l:fpath, "", 10000)
if !append(0, l:lines)
let l:date = strftime("%c")
let l:year = strftime("%Y")
let l:author = "Your Name<xxx@gmail.com>"
let l:filename = expand("%")
let l:incguard = toupper("_" . substitute(l:filename, "\\.", "_", "g"))

silent! exec "%s#\$DATE#". l:date . "#g"
silent! exec "%s#\$YEAR#". l:year . "#g"
silent! exec "%s#\$AUTHOR#". l:author . "#g"
silent! exec "%s#\$FILE_NAME#". l:filename . "#g"
silent! exec "%s#\$INC_GUARD#". l:incguard . "#g"
silent! exec "normal G"
endif
endf

if has("autocmd")
autocmd BufEnter * :cd %:p:h
autocmd BufNewFile *.py call ReadTempl("~/.vim/templ/python.tpl")
autocmd BufNewFile *.h call ReadTempl("~/.vim/templ/cpp_h.tpl")
autocmd BufNewFile *.c,*.cpp call ReadTempl("~/.vim/templ/cpp_m.tpl")
autocmd Bufwritepre,filewritepre *.c,*.cpp,*.h,*.py execute "normal mz"
autocmd Bufwritepre,filewritepre *.c,*.cpp,*.h,*.py exe "1," . 15 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c")
autocmd bufwritepost,filewritepost *.c,*.cpp,*.h,*.py execute "normal `z"
"autocmd! BufNewFile * silent! 0r ~/.vim/skel/Template.%:e
"autocmd BufNewFile *.html 0r ~/.vim/template/html.tpl
endif " has("autocmd")

-------------
python.tpl
#!/usr/bin/python
# -*- coding: utf-8 -*-

# $FILE_NAME - description
# Copyright (C) $YEAR $AUTHOR
# Date : $DATE
# Last Modified :

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/153897

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX