-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc-todo
63 lines (55 loc) · 2.09 KB
/
vimrc-todo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
" Partial vimrc file for keybindings specific to vim-todo
" Utility functions
function! Strip(input_string)
return substitute(a:input_string, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction
function! StripN(input_string)
return substitute(Strip(a:input_string), "\n", "", "")
endfunction
" Select OS-dependent date utility
if has("unix")
let s:uname = system("uname")
if s:uname == "Darwin\n"
" OSX has a dumb date utility, so use the Unix one
" Setting the path in vim seems non-trivial, so directly call the
" correct executable (vs. /bin/date)
let s:dateutil = "/usr/local/opt/coreutils/libexec/gnubin/date"
else
let s:dateutil = "date"
endif
endif
" Insert date into current buffer, given offset from current date
function! InsertDate(offset)
" cmd: date -d'N day' +%a %m-%d-%Y
let l:format = "\'+\\%a \\%m-\\%d-\\%Y\'"
execute ":r !" . s:dateutil . " -d\'". a:offset . " day\' " . l:format
endfunction
command! -nargs=1 InsertDate call InsertDate(<f-args>)
" Insert date in heading format with 80-character bars of "="
function! DateHeading(offset)
let l:bar = "o\<ESC>80i=\<ESC>"
if a:offset == "0"
execute "normal " . l:bar . ":InsertDate " . a:offset . "\<CR>I>> \<ESC>" . l:bar . "o\<ESC>"
else
execute "normal " . l:bar . ":InsertDate " . a:offset . "\<CR>" . l:bar . "o\<ESC>"
endif
endfunction
command! -nargs=1 DateHeading call DateHeading(<f-args>)
" Map function keys to print formatted new dates
noremap <F2> :DateHeading 0<CR>
noremap <F3> :DateHeading 1<CR>
noremap <F4> :DateHeading 2<CR>
noremap <F5> :DateHeading 3<CR>
noremap <F6> :DateHeading 4<CR>
noremap <F7> :DateHeading 5<CR>
noremap <F8> :DateHeading 6<CR>
" Jump to date, given offset from current date
function! GoToDate(offset)
let l:format = "\'+\%a \%m-\%d-\%Y\'"
let l:date = StripN(system(s:dateutil . " -d'". a:offset . " day' " . l:format))
call search(l:date, "w")
endfunction
command! -nargs=1 GoToDate call GoToDate(<f-args>)
command! Today call GoToDate(0)
" Map <Shift-T> to jump to current date
noremap <S-T> :Today<CR>