新建vim脚本自动添加作者信息(脚本)
vim /etc/vimrc
####################尾部添加以下代码###############################
map <F4> ms:call AddAuthor()<cr>‘s
function AddAuthor()
        let n=1
        while n < 5
                let line = getline(n)
                if line =~‘^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$‘
                        call UpdateTitle()
                        return
                endif
                let n = n + 1
        endwhile
        call AddTitle()
endfunction
function UpdateTitle()
        normal m‘
        execute ‘/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@‘
        normal "
        normal mk
        execute ‘/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@‘
        execute "noh"
        normal ‘k
        echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
n AddTitle()
        call append(0,"/**********************************************************")
        call append(1," * Author        : ")
        call append(2," * Email         : ")
        call append(3," * Last modified : ".strftime("%Y-%m-%d %H:%M"))
        call append(4," * Filename      : ".expand("%:t"))
        call append(5," * Description   : ")
        call append(6," * *******************************************************/")
        echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
原文地址:http://jiarh.blog.51cto.com/3467177/1721975