diff options
author | Mike Crute <mike@crute.us> | 2022-03-03 17:20:34 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2022-03-03 17:21:49 -0800 |
commit | 3ddfc76cd3f07af9306a8a4166ab038656ef5726 (patch) | |
tree | 4cfd8da231902a0f962fe10413120ce9d76d55ba /.vim | |
parent | 6b51393d8b6a9f2a6e7a39a41e1fd88bc45a6031 (diff) | |
download | dotfiles-3ddfc76cd3f07af9306a8a4166ab038656ef5726.tar.bz2 dotfiles-3ddfc76cd3f07af9306a8a4166ab038656ef5726.tar.xz dotfiles-3ddfc76cd3f07af9306a8a4166ab038656ef5726.zip |
Add vim interview plugin
Diffstat (limited to '.vim')
-rw-r--r-- | .vim/ftplugin/interview.vim | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/.vim/ftplugin/interview.vim b/.vim/ftplugin/interview.vim new file mode 100644 index 0000000..8b70e70 --- /dev/null +++ b/.vim/ftplugin/interview.vim | |||
@@ -0,0 +1,49 @@ | |||
1 | " InterviewTimestamp inserts a timestamp into an interview file. The timestamp | ||
2 | " is the current HH:MM in 24-hour time and an elapsed time in either seconds | ||
3 | " or minutes from the prior timestamp. | ||
4 | function InterviewTimestamp() | ||
5 | if !exists("*strptime") | ||
6 | echoerr 'Platform has no strptime! InterviewTimestamp will not work.' | ||
7 | return | ||
8 | end | ||
9 | |||
10 | " Insert a blank line if the current line is non-empty | ||
11 | let l:line = line('.') | ||
12 | if getline(l:line) !~ '^$' | ||
13 | call append(l:line, '') | ||
14 | let l:line = l:line + 1 | ||
15 | endif | ||
16 | |||
17 | let l:elapsed = '0s' | ||
18 | let l:nowstr = strftime('%H:%M:%S') | ||
19 | |||
20 | " Seems pointless to re-parse these but in the absence of a date the | ||
21 | " timestamps are only relative to each other so we can't use localtime. We | ||
22 | " also can't assume that we have any other context than what exists in the | ||
23 | " file. | ||
24 | let l:nowtime = strptime('%H:%M:%S', l:nowstr) | ||
25 | |||
26 | " Find a previous timestamp if one exists and calculate min/sec elapsed | ||
27 | let l:prev = search('^#ts ', 'bW') | ||
28 | if l:prev > 0 | ||
29 | let l:parts = split(getline(l:prev)) | ||
30 | let l:prevtime = strptime('%H:%M:%S', l:parts[1]) | ||
31 | |||
32 | let l:elapsed = l:nowtime - l:prevtime | ||
33 | if l:elapsed > 60 | ||
34 | let l:elapsed = l:elapsed / 60 . 'm' | ||
35 | else | ||
36 | let l:elapsed = l:elapsed . 's' | ||
37 | endif | ||
38 | endif | ||
39 | |||
40 | " Insert the timestamp, add a blank line, and move the cursor to that | ||
41 | " line. Assumes we're in insert mode already so the user is ready to type | ||
42 | call append(l:line, '#ts ' . l:nowstr . ' ' . l:elapsed) | ||
43 | call append(l:line + 1, '') | ||
44 | call cursor(l:line + 2, 1) | ||
45 | endfunction | ||
46 | |||
47 | inoremap <buffer> <silent> <leader><enter> <C-O>:call InterviewTimestamp()<CR> | ||
48 | inoremap <buffer> <leader>t TC:<space> | ||
49 | inoremap <buffer> <leader>m ME:<space> | ||