美文网首页
vim配置实现添加文件头和改动更新信息

vim配置实现添加文件头和改动更新信息

作者: 倪桦 | 来源:发表于2022-04-08 21:48 被阅读0次
set number
set autoindent
set tabstop=4
set ai!
set showmatch
set ruler
set incsearch
set foldlevelstart=99 
set backspace=2
set cursorline
autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"
let $author_name = "User"
let $author_email = "eMil@"
let $counts = 0
func SetTitle()
        if &filetype == 'sh'
            call setline(1,"\###################################################################")
            call append(line("."), "\#File Name: ".expand("%"))
            call append(line(".")+1, "\#Author: ".$author_name)
            call append(line(".")+2, "\#mail: ".$author_email)
            call append(line(".")+3, "\#create time   : ".strftime("%c"))
            call append(line(".")+4, "\#last modified : ".strftime("%c"))
            call append(line(".")+5, "\#Update Count  : ".$counts)
            call append(line(".")+6, "\#=============================================================")
            call append(line(".")+7, "\#!/bin/bash")
            call append(line(".")+8, "")
        endif
        if &filetype == 'python'
            call setline(1, "\###################################################################")
            call append(line("."), "\#File Name: ".expand("%"))
            call append(line(".")+1, "\#Author: ".$author_name)
            call append(line(".")+2, "\#mail: ".$author_email)
            call append(line(".")+3, "\#create time   : ".strftime("%c"))
            call append(line(".")+4, "\#last modified : ".strftime("%c"))
            call append(line(".")+5, "\#Update Count : ".$counts)
            call append(line(".")+6, "\#=============================================================")
            call append(line(".")+7, "\#!\#!/bin/python")
            call append(line(".")+8, "")
        endif
        if &filetype == 'R' || &filetype == 'r'
            call setline(1, "\###################################################################")
            call append(line("."), "\#File Name: ".expand("%"))
            call append(line(".")+1, "\#Author: ".$author_name)
            call append(line(".")+2, "\#mail: ".$author_email)
            call append(line(".")+3, "\#create time   : ".strftime("%c"))
            call append(line(".")+4, "\#last modified : ".strftime("%c"))
            call append(line(".")+5, "\#Update Count : ".$counts)
            call append(line(".")+6, "\#=============================================================")
            call append(line(".")+7, "\#!/bin/Rscript --slave")
            call append(line(".")+8, "")
        endif
endfunc
autocmd BufNewFile * normal G

function SetLastModifiedTimes()
    let line = getline(6)
    let newtime = "##last modified : ".strftime("%c")
    let replTime = substitute(line,".*$",newtime,"g")
    call setline(6,replTime)
    %s/\(Update Count\s*:\s*\)\(\d\+\)/\=submatch(1).(submatch(2)+1)/ge
endfunction
autocmd BufWrite *.sh,*.py,*.R,*.r call SetLastModifiedTimes()

相关文章

网友评论

      本文标题:vim配置实现添加文件头和改动更新信息

      本文链接:https://www.haomeiwen.com/subject/vzcusrtx.html