Skip to content

Instantly share code, notes, and snippets.

@joequery
Forked from goatslacker/gist:6004481
Last active December 21, 2015 01:59
Show Gist options
  • Save joequery/6232026 to your computer and use it in GitHub Desktop.
Save joequery/6232026 to your computer and use it in GitHub Desktop.
Create a parseable time tracking log for vim. Requires https://gist.github.com/joequery/6231493 for the `git info` command.
" 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 secs = str2nr(reltimestr(reltime(b:tstart)))
let curFile = expand("%:p")
let time = TimeSpentEditing()
let path = expand("$HOME/.vimtime")
let timestamp = strftime('%s')
let end_timestamp = str2nr(timestamp)
let start_timestamp = end_timestamp - secs
"execute '!echo ' . curFile . ' : ' . time . ' >> ' . path
execute ':silent !echo ' . start_timestamp . '-' . timestamp . ':$(git info):' . curFile . ':[' . time . '] >> ' . path
endfunction
autocmd VimLeave * 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