diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index befa9f0..420760c 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -2087,6 +2087,16 @@ function! vimwiki#base#write_tags_metadata(metadata) "{{{ call writefile(entries, metadata_path) endfunction " }}} +" vimwiki#base#get_tags +" Returns list of unique tags found in metadata +function! vimwiki#base#get_tags(metadata) "{{{ + let tags = {} + for entry in a:metadata + let tags[entry.tagname] = 1 + endfor + return keys(tags) +endfunction " }}} + " }}} " Command completion functions {{{ diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 29dc2a9..313358b 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -49,9 +49,25 @@ function! Complete_wikifiles(findstart, base) return startofinlinelink endif endif + let startoftag = match(line, ':\zs[^:[:space:]]*$') + if startoftag != -1 + return startoftag + endif return -1 else - if a:base !~ '#' + " Completion works for wikilinks/anchors, and for tags. So first we have + " to find out what we're about to complete. + let column = col('.') + let line = getline('.')[:(column - len(a:base))] + let char_before_start = line[-1:-1] + if char_before_start == ':' + " Tags completion + let metadata = vimwiki#base#load_tags_metadata() + let tags = vimwiki#base#get_tags(metadata) + call filter(tags, + \ "v:val[:" . (len(a:base)-1) . "] == '" . substitute(a:base, "'", "''", '') . "'" ) + return tags + elseif a:base !~ '#' " we look for wiki files if a:base =~# '^wiki\d:'