diff --git a/.vim/ExtractWikiLinks.vim b/.vim/ExtractWikiLinks.vim new file mode 100644 index 0000000..67b1e31 --- /dev/null +++ b/.vim/ExtractWikiLinks.vim @@ -0,0 +1,30 @@ +function! ExtractWikiLinks() + let links = [] + let pattern = '\v\[\[([^\]]+)\]\]' + let linenr = 1 + while linenr <= line('$') + let line = getline(linenr) + let match = match(line, pattern) + while match != -1 + let link_start = match + 2 " Start after '[[' + let link_end = matchend(line, pattern) - 2 " End before ']]' + if link_end > link_start + let link = strpart(line, link_start, link_end - link_start) + call add(links, link) + endif + let match = match(line, pattern, matchend(line, pattern)) " Find next match + endwhile + let linenr = linenr + 1 + endwhile + + " Open a new buffer with the extracted links + new + " Make the buffer modifiable temporarily + set modifiable + call setline(1, links) + " Set the buffer options after writing + set nomodifiable buftype=nofile bufhidden=wipe nobuflisted noswapfile + echo "Extracted " . len(links) . " wiki links." +endfunction + +command! ExtractLinks call ExtractWikiLinks()