Added a separate function to extract wiki links It must be sourced on-demand, since it's not tested
31 lines
973 B
VimL
31 lines
973 B
VimL
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()
|