Skip to content

Commit 40c964e

Browse files
committed
Merge branch 'jakemason-feature/automatic_dating' into auto_date_insertion
2 parents 5d2e75f + 3cfe987 commit 40c964e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ function! VimTodoListsCustomMappings()
178178
endfunction
179179
```
180180

181+
Automatic date insertion
182+
------------------------
183+
You can enable automatic date insertion by setting the following in your
184+
.vimrc:
185+
186+
```
187+
let g:VimTodoListsDatesEnabled = 1
188+
```
189+
190+
You can change the format of the date by setting the format variable to a valid
191+
strftime string like so:
192+
193+
```
194+
let g:VimTodoListsDatesFormat = "%a %b, %Y"
195+
```
196+
181197
Future features
182198
---------------
183199

plugin/vim-todo-lists.vim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
" Initializes plugin settings and mappings
2525
function! VimTodoListsInit()
2626
set filetype=todo
27+
28+
if !exists('g:VimTodoListsDatesEnabled')
29+
let g:VimTodoListsDatesEnabled = 0
30+
endif
31+
32+
if !exists('g:VimTodoListsDatesFormat')
33+
let g:VimTodoListsDatesFormat = "%X, %d %b %Y"
34+
endif
35+
2736
setlocal tabstop=2
2837
setlocal shiftwidth=2 expandtab
2938
setlocal cursorline
@@ -325,7 +334,7 @@ function! VimTodoListsSetItemMode()
325334
nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
326335
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
327336
vnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
328-
inoremap <buffer> <CR> <CR><ESC>:VimTodoListsCreateNewItem<CR>
337+
inoremap <buffer> <CR> <ESC>:call VimTodoListsAppendDate()<CR>A<CR><ESC>:VimTodoListsCreateNewItem<CR>
329338
noremap <buffer> <leader>e :silent call VimTodoListsSetNormalMode()<CR>
330339
nnoremap <buffer> <Tab> :VimTodoListsIncreaseIndent<CR>
331340
nnoremap <buffer> <S-Tab> :VimTodoListsDecreaseIndent<CR>
@@ -335,6 +344,12 @@ function! VimTodoListsSetItemMode()
335344
inoremap <buffer> <S-Tab> <ESC>:VimTodoListsDecreaseIndent<CR>A
336345
endfunction
337346

347+
function! VimTodoListsAppendDate()
348+
if(g:VimTodoListsDatesEnabled == 1)
349+
let l:date = strftime(g:VimTodoListsDatesFormat)
350+
execute "s/$/ (" . l:date . ")"
351+
endif
352+
endfunction
338353

339354
" Creates a new item above the current line
340355
function! VimTodoListsCreateNewItemAbove()
@@ -349,7 +364,6 @@ function! VimTodoListsCreateNewItemBelow()
349364
startinsert!
350365
endfunction
351366

352-
353367
" Creates a new item in the current line
354368
function! VimTodoListsCreateNewItem()
355369
normal! 0i- [ ]

0 commit comments

Comments
 (0)