From 66961cae79754f4303056533c091162f211ec0d7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 4 Feb 2020 15:17:59 +0100 Subject: [PATCH] Automatic Zettelkasten note-link naming scheme When creating a new link within notes, using the wiki.vim openlink shortcut (return by default), it will prepend a Zettelkasten-like unique id based on current time in front of the link. It will also lowercase it and substitute spaces for dashes. --- nvim/.config/nvim/plugin/wiki.vim | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/plugin/wiki.vim b/nvim/.config/nvim/plugin/wiki.vim index bdbcbc4..25854cf 100644 --- a/nvim/.config/nvim/plugin/wiki.vim +++ b/nvim/.config/nvim/plugin/wiki.vim @@ -7,6 +7,35 @@ endif " filetypes to automatically enable the plugin for, seems to take file endings " rather than vim ft let g:wiki_filetypes = ['md', 'mkd', 'markdown', 'wiki'] -let g:wiki_link_extension = '.md' -let g:wiki_link_target_type = 'md' let g:wiki_mappings_use_defaults = 1 + +" wiki automatic link creation +" add .md to the end of links by default +let g:wiki_link_extension = '.md' +" add a link in the format [descr](target) by default +" not in wiki format [[link|descr]] +let g:wiki_link_target_type = 'md' + +" Creates a Zettelkasten compatible unique datestamp +function s:Getdatestamp() + if !exists("*strftime") + :echoerr "Date Stamp creation needs strftime available on system!" + endif + return strftime("%y%m%d%H%M") +endfunction + +command! Datestamp :echom s:Getdatestamp() + +" Appends Zettelkasten timestamp to beginning of links +function! PrependDatestamp(text) abort + " lowercase and replace spaces with dashes (-) to make links uniform + let l:text=substitute(tolower(a:text), '\s\+', '-', 'g') + " prepend datestamp + let l:text=substitute(l:text, '^', s:Getdatestamp() . ' '. '\0', 'g') + return l:text +endfunction + +" sets wiki.vim to automatically apply datestamp function to links +let g:wiki_link_target_map = "PrependDatestamp" + +let g:wiki_list_todos = ['[ ]', '[x]']