新建vim腳本自動添加作者信息(腳本)

新建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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章