Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
time tracking local
" Lets me know how much time I've spent editing a file
" Keyboard shortcut -> \dt
augroup TimeSpentEditing
au!
au BufWinEnter * if !exists('b:tstart')|let b:tstart=reltime()|en
augroup END
function! TimeSpentEditing()
let secs = str2nr(reltimestr(reltime(b:tstart)))
let hours = secs / 3600
let minutes = (secs - hours * 3600) / 60
let seconds = secs - hours * 3600 - minutes * 60
return printf("%d:%02d:%02d", hours, minutes, seconds)
endfunction
function! s:logTimespent()
let curFile = expand("%:p")
let time = TimeSpentEditing()
let path = expand("$HOME/.vimtime")
execute ":silent !echo " . curFile . " : " . time . " >> " . path
endfunction
autocmd BufWritePost * call s:logTimespent()
com! TimeSpentEditing echo TimeSpentEditing()
map <silent> <leader>dt :TimeSpentEditing<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.