zeroday
V2EX  ›  问与答

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

  •  
  •   zeroday · Dec 14, 2014 · 5958 views
    This topic created in 4261 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Dec 15, 2014
    刚刚发现这个插件,觉得还不错。
    https://github.com/aperezdc/vim-template
    4 replies    2014-12-15 10:15:14 +08:00
    jiang42
        1
    jiang42  
       Dec 14, 2014
    同求,现在是用UltiSnips 添加,也还行
    jwk345
        2
    jwk345  
       Dec 14, 2014
    1、http://www.vim.org/scripts/script.php?script_id=4786
    2、参考:au BufNewFile *.py 0r ~/.vim/skeletons/skel.python
    weegc
        3
    weegc  
       Dec 15, 2014
    试试snipmate
    josephpei
        4
    josephpei  
       Dec 15, 2014   ❤️ 1
    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<[email protected]>"
    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 :
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1175 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:58 · PVG 07:58 · LAX 16:58 · JFK 19:58
    ♥ Do have faith in what you're doing.