ExtractWikiLinks
Added a separate function to extract wiki links It must be sourced on-demand, since it's not tested
This commit is contained in:
30
.vim/ExtractWikiLinks.vim
Normal file
30
.vim/ExtractWikiLinks.vim
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user