summary refs log tree commit diff
path: root/.vim/plugin/zettel.vim
blob: 948bb916e891dcdb440de51914b3b62b3f2908ee (plain) (blame)
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
" markdown extended for bullet journaling and personal wiki-keeping

if exists('g:loaded_zettel')
	finish
endif
let g:loaded_zettel = 1

if !exists('g:zettel_root')
	let g:zettel_root = expand($HOME.'/wiki')
endif

if !exists('g:zettel_create_on_empty')
	let g:zettel_create_on_emtpy = 1
endif

if v:progname =~ 'vimdiff'
	let g:zettel_create_on_empty = 0
endif

function! <SID>make_new_zettel()
	let l:pastebackup = &paste
	set nopaste

	0 put ='---'
	read !yq n date $(date -Iseconds) | yq w - title "%:t:r"
	put ='---'
	call feedkeys('Go', 'n')

	if pastebackup == 0
		set nopaste
	endif
endfunction

command! -nargs=0 NewZettel call <SID>make_new_zettel()

augroup NewZettel
	au!
	au BufNewFile *.md
		\ if expand('%:p') =~# fnameescape(g:zettel_root).'/.*.md' |
		\ 	call <SID>make_new_zettel() |
		\ endif
augroup END