autocmd! BufWritePost *.md,*.mkd,*.markdown :silent!call Insertimg()<CR> function! Insertimg() " 转换![name](num) :%s#\(!\[[^\]]*\](\)\(\w\{,10}\))#\=submatch(1).'http://7xsj4f.com2.z0.glb.clouddn.com/'.expand("%:r").'/'.submatch(2).'.png)'# " 转换 ![name][num] let lnum = 1 let lst = [] while lnum <= line("$") let line = getline(lnum) call substitute(line, '\(!\[[^\]]*\]\[\)\(\d\{,2}\)\]', '\=add(lst, submatch(2))', 'g') let lnum += 1 endwhile let unduplst=sort(filter(copy(lst),'index(lst, v:val, v:key+1)==-1')) let line = getline(line("$")) let flag = matchstr(line,'\[\d\+\]: http:') :ks while flag != '' exe "normal G" exe "normal dd" let line = getline(line("$")) let flag = matchstr(line,'\[\d\+\]: http:') endwhile exe "normal 's"
for name in unduplst if len(name)>0 call append(line("$"), "[".name."]: http://7xsj4f.com2.z0.glb.clouddn.com/".expand("%:r")."/".name.".png") endif endfor :w endfunction