【发布时间】:2011-03-09 19:42:36
【问题描述】:
我正在努力养成使用一个编辑器(Windows XP 上的 gVim 7.3)完成所有编程和开发任务的习惯。
我想在使用 :w 保存时更新任何打开文件中的标题
标题如下所示(在 C 文件中):
/* Filename: hello.c
* Filesize: 345 bytes
* Last Modified: Fri Feb 25, 2011 01:55PM
*/
我实际上已经想出了如何更新 Last Modified,方法是在我的 _vimrc 文件中包含以下内容:
" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: ' can have up to 10 characters before (they are retained).
" Restores cursor and window position using save_cursor variable.
function! LastModified()
if &modified
let save_cursor = getpos(".")
let n = min([20, line("$")])
keepjumps exe '1,' . n . 's#^\(.\{,10}Last Modified:\).*#\1' .
\ strftime(' %a %b %d, %Y %I:%M%p') . '#e'
call histdel('search', -1)
call setpos('.', save_cursor)
endif
endfun
autocmd BufWritePre * call LastModified()
我的问题是,使用类似的方法,我怎样才能同时更新文件名和文件大小?感谢您的帮助。
【问题讨论】:
-
为什么要这样做?您的版本控制系统存储相同的信息,因此您只需手动复制自动保存的内容...
标签: vim configuration header editor