目的
每次修改文件后,希望在文件头上的反应出最后修改时间,并更新修改次数
主要语法
submatch(n)
引用前面匹配的内容, submatch(0)是全部, submatch(1)是第一个
getpos(".")
得到当前光标位置
setpos(‘.', save_cursor)用来恢复位置
winsaveview()
保存整个layout
实际代码
function TimeStamp()
" let save_cursor= getpos(".")
let win_view = winsaveview()
%s/\(Last Change\s*:\s*\)\(.*\)$/\=submatch(1).strftime("%Y-%m-%d %H:%M:%S")/ge
%s/\(Last Modified\s*:\s*\)\(.*\)$/\=submatch(1).strftime("%Y-%m-%d %H:%M:%S")/ge
%s/\(Update Count\s*:\s*\)\(\d\+\)/\=submatch(1).(submatch(2)+1)/ge
" call setpos('.', save_cursor)
call winrestview(win_view)
endfunction
command -nargs=0 TimeStamp call TimeStamp()
function AutoTimeStamp()
augr tagdate
au!
au BufWritePost,FileWritePost * call TimeStamp()
augr END
endfunction
command -nargs=0 AutoTimeStamp call AutoTimeStamp()
if !exists('*Preserve_view')
function! Preserve_view(command)
" Preparation: save last search, and cursor position.
let win_view = winsaveview()
let old_query = getreg('/')
execute 'keepjumps ' . a:command
" Clean up: restore previous search history, and cursor position
call winrestview(win_view)
call setreg('/', old_query)
endfunction
endif
fun! CleanExtraSpaces()
call Preserve_view('%s/\s\+$//ge')
endfunc
com! Clsspace :call CleanExtraSpaces()
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。