vim配置实现添加文件头和改动更新信息
2022-04-08 本文已影响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()